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

Closed
Fuzzo opened this issue Dec 6, 2024 · 1 comment
Closed

Generic method to fetch all collection elements with v6 #2248

Fuzzo opened this issue Dec 6, 2024 · 1 comment
Assignees
Labels
type:question An issue that's a question

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
@Ndiritu
Copy link
Contributor

Ndiritu commented Dec 17, 2024

Hi @Fuzzo
The SDK provides a Page Iterator that allows you to fetch each page and execute a callback on each item should you prefer. Feel free to look at the linked docs and provide any feedback.

@Ndiritu Ndiritu added type:question An issue that's a question status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned type:feature New experience request labels Dec 17, 2024
@Ndiritu Ndiritu assigned Ndiritu and unassigned Ndiritu Dec 17, 2024
@Ndiritu Ndiritu closed this as completed Dec 17, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question An issue that's a question
Projects
None yet
Development

No branches or pull requests

2 participants