Skip to content

Commit

Permalink
Merge pull request #44 from JesseMckinzie/java_groupby
Browse files Browse the repository at this point in the history
Fix groupby in iterator
  • Loading branch information
sameeul authored Oct 31, 2023
2 parents e808977 + 338dd6c commit 44660c0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/filepattern/java/FilePattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public Iterator<?> iterator() {
*/
public Iterator<?> iterator(String ... groups) {

this.fp.setGroup(new FilePatternBindings.StringVector(groups));
this.setGroup(groups);

return new FilePatternGroupedIterator(this);

Expand Down
34 changes: 33 additions & 1 deletion tests/java/TestFilePattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testGetMatching() {
}

@Test
public void testGroupBy() {
public void testSetGroup() {

FilePattern fp = null;
try {
Expand Down Expand Up @@ -119,4 +119,36 @@ public void testGroupBy() {

}

@Test
public void testGroupBy() {

FilePattern fp = null;
try {
fp = new FilePattern.FilePatternBuilder("test_fp_data")
.recursive(false)
.filePattern("img_r00{r:d}_c00{c:d}_{channel:c+}.tif")
.suppressWarnings(false)
.blockSize("")
.recursive(false).build();
} catch (Exception e) {
fail("Error creating FilePattern object.");
}

ArrayList<Pair<ArrayList<Pair<String, Object>>, ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>>>> result = new ArrayList<>();


for (Iterator<?> i = fp.iterator("r"); i.hasNext(); ) {
result.add((Pair<ArrayList<Pair<String, Object>>, ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>>>) i.next());
}

ArrayList<Pair<ArrayList<Pair<String, Object>>, ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>>>> truth = TestData.getGroupedResults();

System.out.println(result.size());
System.out.println(truth.size());

assertEquals(result.size(), truth.size());
assertEquals(result, truth);

}

}

0 comments on commit 44660c0

Please sign in to comment.