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

Make FilteredIterator::hasNext idempotent #1174

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,27 @@ private static class FilteredIterator implements Iterator<MFile> {
this.mc = mc;
this.wantDirs = wantDirs;
this.fullInventory = false;
this.next = nextFilteredFile();
}

FilteredIterator(CollectionConfig mc, Iterator<MFile> iter, boolean wantDirs, boolean fullInventory) {
this.orgIter = iter;
this.mc = mc;
this.wantDirs = wantDirs;
this.fullInventory = fullInventory;
this.next = nextFilteredFile();
}

public boolean hasNext() {
next = nextFilteredFile();
return (next != null);
}

public MFile next() {
if (next == null)
throw new NoSuchElementException();
return next;
final MFile mFile = next;
next = nextFilteredFile();
return mFile;
}

public void remove() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ public static void setup() {

}

@Test
public void shouldReturnSameValueFromHasNext() throws URISyntaxException {
final CdmS3Uri uri = new CdmS3Uri("cdms3:thredds-test-data");
final MFileFilter filter = new WildcardMatchOnName("testData.nc");
final CollectionConfig collectionConfig = new CollectionConfig(uri.getBucket(), uri.toString(), true, filter, null);
final ControllerS3 controller = new ControllerS3();
final Iterator<MFile> iterator = controller.getInventoryTop(collectionConfig, false);

assertThat(iterator.hasNext()).isTrue();
assertThat(iterator.hasNext()).isTrue();
iterator.next();
assertThat(iterator.hasNext()).isFalse();
assertThat(iterator.hasNext()).isFalse();
}

//////////////////////
// getInventoryTop() tests
//
Expand Down