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

Studio-NDTiffAdapter: Simplifies function getImagesMatching() #1840

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Changes from 1 commit
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 @@ -222,30 +222,28 @@ public Iterable<Coords> getUnorderedImageCoords() {
};
}

/**
* This implementation only check for an exact match. It does not actually return a list
* of all images that match the given coordinates, as I am not quite sure how to implement that.
*
* @param coords Coordinates specifying images to match
* @return List of images matching the coordinates
* @throws IOException can always happen.
*/
@Override
public List<Image> getImagesMatching(Coords coords) throws IOException {
List<Image> imageList = new LinkedList<>();
if (storage_ == null) {
return new LinkedList<Image>();
return imageList;
}
Stream<HashMap<String, Object>> axesStream = storage_.getAxesSet().stream();
axesStream = axesStream.filter(stringIntegerHashMap -> {
for (String axis : coords.getAxes()) {
if (!stringIntegerHashMap.containsKey(axis)) {
return false;
} else if ((Integer) stringIntegerHashMap.get(axis) != coords.getIndex(axis)) {
return false;
}
}
return true;
});
return axesStream.map(new Function<HashMap<String, Object>, Image>() {
@Override
public Image apply(HashMap<String, Object> axes) {
TaggedImage ti = addEssentialImageMetadata(storage_.getImage(axes), axes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line that I think would need to change

return new DefaultImage(ti, hashMapToCoords(axes),
studioMetadataFromJSON(ti.tags));
}
}).collect(Collectors.toList());
HashMap<String, Object> ndTiffCoords = coordsToHashMap(coords);
if (storage_.hasImage(ndTiffCoords)) {
TaggedImage ti = addEssentialImageMetadata(storage_.getImage(ndTiffCoords), ndTiffCoords);
Image img = new DefaultImage(ti, hashMapToCoords(ndTiffCoords),
studioMetadataFromJSON(ti.tags));
imageList.add(img);
}
return imageList;
}

@Override
Expand All @@ -258,7 +256,7 @@ public List<Image> getImagesIgnoringAxes(

@Override
public int getMaxIndex(String axis) {
if (storage_ == null || storage_.getAxesSet() == null || storage_.getAxesSet().size() == 0) {
if (storage_ == null || storage_.getAxesSet() == null || storage_.getAxesSet().isEmpty()) {
return -1;
}
return storage_.getAxesSet().stream().map(new Function<HashMap<String, Object>, Integer>() {
Expand Down
Loading