Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic method to fetch all collection elements with v6 #2248

Open
Fuzzo opened this issue Dec 6, 2024 · 0 comments
Open

Generic method to fetch all collection elements with v6 #2248

Fuzzo opened this issue Dec 6, 2024 · 0 comments
Labels
status:waiting-for-triage An issue that is yet to be reviewed or assigned type:feature New experience request

Comments

@Fuzzo
Copy link

Fuzzo commented Dec 6, 2024

Is your feature request related to a problem? Please describe the problem.

I am trying to write a generic method to fetch all elements of a collection. With v5 it was pretty easy:

public static <T, B extends BaseCollectionRequestBuilder<T, ?, ?, ?, ?>> List<T> fetchWholeCollection(B builder, Option... opt) {
  Objects.requireNonNull(builder);
  List<T> allObj = new ArrayList<>();
  int i=0;
  while (builder != null) {
	  BaseEntityCollectionRequest<T, ?, ?> req = (BaseEntityCollectionRequest<T, ?, ?>) builder.buildRequest(opt);
	  LOG.trace("#{} Url:          {}", i, req.getRequestUrl());
	  BaseCollectionPage<T, ?> page = req.get();
	  List<T> chunk = page.getCurrentPage();
	  LOG.trace("#{} Count:        {}", i, chunk.size());
	  allObj.addAll(chunk);
	  LOG.trace("#{} All count:    {}", i, allObj.size());
	  builder = (B) page.getNextPage();
	  if (builder != null) {
		  LOG.trace("#{} Next builder: {}", i, builder.getRequestUrl());
		  i++;
	  } else {
		  LOG.trace("#{} Last call!", i);
	  }
  }
  return allObj;
}

How I can write a similar generic method with v6?
What I'm doing wrong?
Thanks

Describe the solution you'd like.

A common base class to be used to fetch all elements of a collection

Additional context?

No response

@Fuzzo Fuzzo added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:feature New experience request labels Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:waiting-for-triage An issue that is yet to be reviewed or assigned type:feature New experience request
Projects
None yet
Development

No branches or pull requests

1 participant