diff --git a/src/main/java/fr/igred/omero/Annotatable.java b/src/main/java/fr/igred/omero/Annotatable.java index 720b0e56..4e528202 100644 --- a/src/main/java/fr/igred/omero/Annotatable.java +++ b/src/main/java/fr/igred/omero/Annotatable.java @@ -19,7 +19,6 @@ import fr.igred.omero.annotations.Annotation; -import fr.igred.omero.annotations.AnnotationList; import fr.igred.omero.annotations.FileAnnotation; import fr.igred.omero.annotations.MapAnnotation; import fr.igred.omero.annotations.RatingAnnotation; @@ -69,8 +68,10 @@ public interface Annotatable extends RemoteObject { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - boolean isLinked(Browser browser, A annotation) - throws ServiceException, AccessException, ExecutionException; + default boolean isLinked(Browser browser, A annotation) + throws ServiceException, AccessException, ExecutionException { + return getAnnotations(browser).stream().anyMatch(a -> a.getId() == annotation.getId()); + } /** @@ -606,14 +607,8 @@ default List getAnnotationData(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default AnnotationList getAnnotations(Browser browser) - throws AccessException, ServiceException, ExecutionException { - List annotationData = getAnnotationData(browser); - - AnnotationList annotations = new AnnotationList(annotationData.size()); - annotationData.forEach(annotations::add); - return annotations; - } + List getAnnotations(Browser browser) + throws AccessException, ServiceException, ExecutionException; /** diff --git a/src/main/java/fr/igred/omero/AnnotatableWrapper.java b/src/main/java/fr/igred/omero/AnnotatableWrapper.java index 1bacfb64..2b5612bb 100644 --- a/src/main/java/fr/igred/omero/AnnotatableWrapper.java +++ b/src/main/java/fr/igred/omero/AnnotatableWrapper.java @@ -34,6 +34,7 @@ import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.util.ReplacePolicy; +import fr.igred.omero.util.Wrapper; import omero.gateway.model.AnnotationData; import omero.gateway.model.DataObject; import omero.gateway.model.FileAnnotationData; @@ -83,26 +84,6 @@ protected AnnotatableWrapper(T o) { protected abstract String annotationLinkType(); - /** - * Checks if a specific annotation is linked to the object. - * - * @param browser The data browser. - * @param annotation Annotation to be checked. - * @param The type of the annotation. - * - * @return True if the object is linked to the given annotation, false otherwise. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - @Override - public boolean isLinked(Browser browser, A annotation) - throws ServiceException, AccessException, ExecutionException { - return getAnnotations(browser).stream().anyMatch(a -> a.getId() == annotation.getId()); - } - - /** * Adds a newly created tag to the object in OMERO, if possible. * @@ -550,4 +531,22 @@ protected void removeLink(Client client, String linkType, long childId) removeLinks(client, linkType, singletonList(childId)); } + + /** + * Retrieves annotations linked to the object (of known types). + * + * @param browser The data browser. + * + * @return A list of annotations. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + @Override + public List getAnnotations(Browser browser) + throws AccessException, ServiceException, ExecutionException { + return wrap(getAnnotationData(browser), Wrapper::wrap); + } + } diff --git a/src/main/java/fr/igred/omero/RemoteObject.java b/src/main/java/fr/igred/omero/RemoteObject.java index 951af57a..6b610123 100644 --- a/src/main/java/fr/igred/omero/RemoteObject.java +++ b/src/main/java/fr/igred/omero/RemoteObject.java @@ -26,11 +26,11 @@ import java.sql.Timestamp; import java.util.Collection; -import java.util.Comparator; import java.util.List; import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; +import static java.util.Comparator.comparing; +import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toMap; @@ -39,6 +39,26 @@ */ public interface RemoteObject { + + /** + * Gets a list of elements of the specified class from a collection of RemoteObjects. + * + * @param clazz Class of the wanted elements. + * @param collection The collection of RemoteObjects + * @param Subclass of RemoteObject. + * @param Subclass of U. + * + * @return See above. + */ + static List getElementsOf(Collection collection, + Class clazz) { + return collection.stream() + .filter(clazz::isInstance) + .map(clazz::cast) + .collect(toList()); + } + + /** * Only keeps objects with different IDs in a collection. * @@ -52,8 +72,8 @@ static List distinct(Collection objects .collect(toMap(T::getId, o -> o, (o1, o2) -> o1)) .values() .stream() - .sorted(Comparator.comparing(T::getId)) - .collect(Collectors.toList()); + .sorted(comparing(T::getId)) + .collect(toList()); } @@ -61,19 +81,19 @@ static List distinct(Collection objects * Flattens a collection of collections and only keeps objects with different IDs. * * @param lists A collection of objects collections. - * @param The objects type. + * @param The objects type. * * @return Distinct objects list, sorted by ID. */ - static - List flatten(Collection> lists) { + static + List flatten(Collection> lists) { return lists.stream() .flatMap(Collection::stream) - .collect(toMap(U::getId, o -> o, (o1, o2) -> o1)) + .collect(toMap(T::getId, o -> o, (o1, o2) -> o1)) .values() .stream() - .sorted(Comparator.comparing(U::getId)) - .collect(Collectors.toList()); + .sorted(comparing(T::getId)) + .collect(toList()); } diff --git a/src/main/java/fr/igred/omero/annotations/AnnotationList.java b/src/main/java/fr/igred/omero/annotations/AnnotationList.java deleted file mode 100644 index ed150deb..00000000 --- a/src/main/java/fr/igred/omero/annotations/AnnotationList.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2020-2024 GReD - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin - * Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package fr.igred.omero.annotations; - - -import omero.gateway.model.AnnotationData; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import static fr.igred.omero.util.Wrapper.wrap; - - -/** List of AnnotationWrapper objects */ -public class AnnotationList extends ArrayList { - - - private static final long serialVersionUID = 8792604507462788823L; - - - /** - * Constructs an empty list with an initial capacity of ten. - */ - public AnnotationList() { - } - - - /** - * Constructs an empty list with the specified initial capacity. - * - * @param initialCapacity the initial capacity of the list - * - * @throws IllegalArgumentException if the specified initial capacity is negative - */ - public AnnotationList(int initialCapacity) { - super(initialCapacity); - } - - - /** - * Gets a list of elements from this list whose class is specified. - * - * @param clazz Class of the wanted elements. - * @param Subclass of AnnotationWrapper. - * - * @return See above. - */ - public List getElementsOf(Class clazz) { - return stream().filter(clazz::isInstance) - .map(clazz::cast) - .collect(Collectors.toList()); - } - - - /** - * Wraps the specified AnnotationData object and add it to the end of this list. - * - * @param shape element to be wrapped and appended to this list - * - * @return {@code true} (as specified by {@link ArrayList#add(Object)}) - */ - public boolean add(AnnotationData shape) { - boolean added; - - try { - added = add(wrap(shape)); - } catch (IllegalArgumentException e) { - added = false; - } - - return added; - } - -} diff --git a/src/main/java/fr/igred/omero/core/PlaneInfoWrapper.java b/src/main/java/fr/igred/omero/core/PlaneInfoWrapper.java index 91b921db..05f4bf37 100644 --- a/src/main/java/fr/igred/omero/core/PlaneInfoWrapper.java +++ b/src/main/java/fr/igred/omero/core/PlaneInfoWrapper.java @@ -24,6 +24,10 @@ import omero.model.Time; +/** + * Class containing a PlaneInfoData object. + *

Wraps function calls to the PlaneInfoData contained. + */ public class PlaneInfoWrapper extends ObjectWrapper implements PlaneInfo { /** diff --git a/src/main/java/fr/igred/omero/roi/ROI.java b/src/main/java/fr/igred/omero/roi/ROI.java index 371e1fd9..42e8932e 100644 --- a/src/main/java/fr/igred/omero/roi/ROI.java +++ b/src/main/java/fr/igred/omero/roi/ROI.java @@ -261,7 +261,7 @@ default void addShapes(Iterable shapes) { * * @return list of shape contained in the ROIData. */ - ShapeList getShapes(); + List getShapes(); /** diff --git a/src/main/java/fr/igred/omero/roi/ROIWrapper.java b/src/main/java/fr/igred/omero/roi/ROIWrapper.java index d7521908..bb37f834 100644 --- a/src/main/java/fr/igred/omero/roi/ROIWrapper.java +++ b/src/main/java/fr/igred/omero/roi/ROIWrapper.java @@ -23,6 +23,7 @@ import fr.igred.omero.core.Image; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; +import fr.igred.omero.util.Wrapper; import ij.gui.PointRoi; import ij.gui.ShapeRoi; import omero.RString; @@ -33,7 +34,6 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -222,13 +222,8 @@ public void addShape(Shape shape) { * @return list of shape contained in the ROIData. */ @Override - public ShapeList getShapes() { - List shapeData = data.getShapes(); - ShapeList shapes = new ShapeList(shapeData.size()); - shapeData.stream() - .sorted(Comparator.comparing(ShapeData::getId)) - .forEachOrdered(shapes::add); - return shapes; + public List getShapes() { + return wrap(data.getShapes(), Wrapper::wrap); } @@ -298,7 +293,7 @@ public List toImageJ(String property) { String ijNameProperty = ROI.ijNameProperty(property); String roiID = String.valueOf(getId()); - ShapeList shapes = getShapes(); + List shapes = getShapes(); Map> sameSlice = shapes.stream() .collect(groupingBy(Shape::getCZT, diff --git a/src/main/java/fr/igred/omero/roi/ShapeList.java b/src/main/java/fr/igred/omero/roi/ShapeList.java deleted file mode 100644 index 2cdb4a21..00000000 --- a/src/main/java/fr/igred/omero/roi/ShapeList.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2020-2024 GReD - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin - * Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package fr.igred.omero.roi; - - -import omero.gateway.model.ShapeData; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import static fr.igred.omero.util.Wrapper.wrap; - - -/** List of ShapeWrapper objects */ -public class ShapeList extends ArrayList { - - - private static final long serialVersionUID = -5942132062803749727L; - - - /** - * Constructs an empty list with an initial capacity of ten. - */ - public ShapeList() { - } - - - /** - * Constructs an empty list with the specified initial capacity. - * - * @param initialCapacity the initial capacity of the list - * - * @throws IllegalArgumentException if the specified initial capacity is negative - */ - public ShapeList(int initialCapacity) { - super(initialCapacity); - } - - - /** - * Gets a list of elements from this list whose class is specified. - * - * @param clazz Class of the wanted elements. - * @param Subclass of ShapeWrapper. - * - * @return See above. - */ - public List getElementsOf(Class clazz) { - return stream().filter(clazz::isInstance) - .map(clazz::cast) - .collect(Collectors.toList()); - } - - - /** - * Wraps the specified ShapeData object and add it to the end of this list. - * - * @param shape element to be wrapped and appended to this list - * - * @return {@code true} (as specified by {@link ArrayList#add(Object)}) - */ - public boolean add(ShapeData shape) { - boolean added; - - try { - added = add(wrap(shape)); - } catch (IllegalArgumentException e) { - added = false; - } - - return added; - } - -} diff --git a/src/main/java/fr/igred/omero/roi/ShapeWrapper.java b/src/main/java/fr/igred/omero/roi/ShapeWrapper.java index 18e165f6..9c63111e 100644 --- a/src/main/java/fr/igred/omero/roi/ShapeWrapper.java +++ b/src/main/java/fr/igred/omero/roi/ShapeWrapper.java @@ -35,6 +35,7 @@ import java.awt.Font; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.LinkedList; @@ -81,9 +82,9 @@ protected ShapeWrapper(T s) { * * @return A list of shapes. */ - static ShapeList fromImageJ(ij.gui.Roi ijRoi) { - ShapeList list = new ShapeList(); - int type = ijRoi.getType(); + static List fromImageJ(ij.gui.Roi ijRoi) { + List list = new ArrayList<>(ijRoi.size()); + int type = ijRoi.getType(); switch (type) { case Roi.FREEROI: case Roi.TRACED_ROI: diff --git a/src/test/java/fr/igred/omero/annotations/RatingAnnotationTest.java b/src/test/java/fr/igred/omero/annotations/RatingAnnotationTest.java index c106403d..1eb0368d 100644 --- a/src/test/java/fr/igred/omero/annotations/RatingAnnotationTest.java +++ b/src/test/java/fr/igred/omero/annotations/RatingAnnotationTest.java @@ -26,6 +26,7 @@ import java.util.List; +import static fr.igred.omero.RemoteObject.getElementsOf; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -41,8 +42,7 @@ void testAddRating1() throws Exception { RatingAnnotation rating = new RatingAnnotationWrapper(score); image.link(client, rating); - List ratings = image.getAnnotations(client) - .getElementsOf(RatingAnnotation.class); + List ratings = getElementsOf(image.getAnnotations(client), RatingAnnotation.class); client.delete(ratings); assertEquals(1, ratings.size()); @@ -59,8 +59,7 @@ void testAddRating2() throws Exception { rating.setRating(score); image.link(client, rating); - List ratings = image.getAnnotations(client) - .getElementsOf(RatingAnnotation.class); + List ratings = getElementsOf(image.getAnnotations(client), RatingAnnotation.class); client.delete(ratings); assertEquals(1, ratings.size()); @@ -72,15 +71,14 @@ void testAddRating2() throws Exception { void testRate1() throws Exception { Image image = client.getImage(IMAGE1.id); int score1 = 4; - int score2 = 3; + int score2 = 3; image.rate(client, score1); int rating1 = image.getMyRating(client); image.rate(client, score2); int rating2 = image.getMyRating(client); - List ratings = image.getAnnotations(client) - .getElementsOf(RatingAnnotation.class); + List ratings = getElementsOf(image.getAnnotations(client), RatingAnnotation.class); client.delete(ratings); assertEquals(1, ratings.size()); @@ -93,8 +91,8 @@ void testRate1() throws Exception { void testRate2() throws Exception { Image image = client.getImage(IMAGE1.id); int score0 = 1; - int score1 = 2; - int score2 = 3; + int score1 = 2; + int score2 = 3; RatingAnnotation rating1 = new RatingAnnotationWrapper(new RatingAnnotationData()); rating1.setRating(score0); @@ -106,8 +104,7 @@ void testRate2() throws Exception { image.rate(client, score2); int myRating2 = image.getMyRating(client); - List ratings = image.getAnnotations(client) - .getElementsOf(RatingAnnotation.class); + List ratings = getElementsOf(image.getAnnotations(client), RatingAnnotation.class); client.delete(ratings); assertEquals(1, ratings.size()); @@ -120,15 +117,14 @@ void testRate2() throws Exception { void testRate3() throws Exception { Dataset dataset = client.getDataset(DATASET1.id); int score1 = 4; - int score2 = 3; + int score2 = 3; dataset.rate(client, score1); int rating1 = dataset.getMyRating(client); dataset.rate(client, score2); int rating2 = dataset.getMyRating(client); - List ratings = dataset.getAnnotations(client) - .getElementsOf(RatingAnnotation.class); + List ratings = getElementsOf(dataset.getAnnotations(client), RatingAnnotation.class); client.delete(ratings); assertEquals(1, ratings.size()); diff --git a/src/test/java/fr/igred/omero/annotations/TextualAnnotationTest.java b/src/test/java/fr/igred/omero/annotations/TextualAnnotationTest.java index b4e00a8c..ccf894b6 100644 --- a/src/test/java/fr/igred/omero/annotations/TextualAnnotationTest.java +++ b/src/test/java/fr/igred/omero/annotations/TextualAnnotationTest.java @@ -24,6 +24,7 @@ import java.util.List; +import static fr.igred.omero.RemoteObject.getElementsOf; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -39,9 +40,9 @@ void testAddTextualAnnotation1() throws Exception { TextualAnnotation text = new TextualAnnotationWrapper(test); image.link(client, text); - AnnotationList annotations = image.getAnnotations(client); + List annotations = image.getAnnotations(client); - List texts = annotations.getElementsOf(TextualAnnotation.class); + List texts = getElementsOf(annotations, TextualAnnotation.class); client.delete(texts); assertEquals(1, texts.size()); @@ -58,9 +59,9 @@ void testAddTextualAnnotation2() throws Exception { TextualAnnotation text = new TextualAnnotationWrapper("New"); text.setText(test); image.link(client, text); - AnnotationList annotations = image.getAnnotations(client); + List annotations = image.getAnnotations(client); - List texts = annotations.getElementsOf(TextualAnnotation.class); + List texts = getElementsOf(annotations, TextualAnnotation.class); client.delete(texts); assertEquals(1, texts.size()); diff --git a/src/test/java/fr/igred/omero/core/ImageTest.java b/src/test/java/fr/igred/omero/core/ImageTest.java index 15a88225..84f7ba5a 100644 --- a/src/test/java/fr/igred/omero/core/ImageTest.java +++ b/src/test/java/fr/igred/omero/core/ImageTest.java @@ -19,7 +19,7 @@ import fr.igred.omero.UserTest; -import fr.igred.omero.annotations.AnnotationList; +import fr.igred.omero.annotations.Annotation; import fr.igred.omero.annotations.FileAnnotation; import fr.igred.omero.annotations.MapAnnotation; import fr.igred.omero.annotations.MapAnnotationWrapper; @@ -153,7 +153,7 @@ void testGetWellSamples() throws Exception { @Test void testGetAnnotations() throws Exception { - AnnotationList annotations = client.getImage(IMAGE1.id).getAnnotations(client); + List annotations = client.getImage(IMAGE1.id).getAnnotations(client); assertEquals(3, annotations.size()); } diff --git a/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java b/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java index b72a9b9d..0e6f6f74 100644 --- a/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java +++ b/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java @@ -44,6 +44,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import static fr.igred.omero.RemoteObject.getElementsOf; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; @@ -228,7 +229,7 @@ void convertEllipse() { ROI roi = ROIWrapper.fromImageJ(roiList).get(0); - Ellipse newEllipse = roi.getShapes().getElementsOf(Ellipse.class).get(0); + Ellipse newEllipse = getElementsOf(roi.getShapes(), Ellipse.class).get(0); assertEquals(ellipse.getX(), newEllipse.getX(), Double.MIN_VALUE); assertEquals(ellipse.getY(), newEllipse.getY(), Double.MIN_VALUE); @@ -252,7 +253,7 @@ void convertRectangle() { roiList.add(ijRectangle); ROI roi = ROIWrapper.fromImageJ(roiList, null).get(0); - Rectangle newRectangle = roi.getShapes().getElementsOf(Rectangle.class).get(0); + Rectangle newRectangle = getElementsOf(roi.getShapes(), Rectangle.class).get(0); assertEquals(rectangle.getX(), newRectangle.getX(), Double.MIN_VALUE); assertEquals(rectangle.getY(), newRectangle.getY(), Double.MIN_VALUE); @@ -282,7 +283,7 @@ void convertArrow() { roiList.add(ijArrow); ROI roi = ROIWrapper.fromImageJ(roiList, "").get(0); - fr.igred.omero.roi.Line newArrow = roi.getShapes().getElementsOf(Line.class).get(0); + fr.igred.omero.roi.Line newArrow = getElementsOf(roi.getShapes(), Line.class).get(0); assertEquals(arrow.getX1(), newArrow.getX2(), Double.MIN_VALUE); assertEquals(arrow.getY1(), newArrow.getY2(), Double.MIN_VALUE); @@ -313,7 +314,7 @@ void convertLine() { roiList.add(ijLine); ROI roi = ROIWrapper.fromImageJ(roiList, ROI.IJ_PROPERTY).get(0); - fr.igred.omero.roi.Line newLine = roi.getShapes().getElementsOf(Line.class).get(0); + Line newLine = getElementsOf(roi.getShapes(), Line.class).get(0); assertEquals(line.getX1(), newLine.getX1(), Double.MIN_VALUE); assertEquals(line.getY1(), newLine.getY1(), Double.MIN_VALUE); @@ -349,7 +350,7 @@ void convertMask() { roiList.add(imgRoi); ROI roi = ROIWrapper.fromImageJ(roiList).get(0); - Mask newMask = roi.getShapes().getElementsOf(Mask.class).get(0); + Mask newMask = getElementsOf(roi.getShapes(), Mask.class).get(0); int[][] checkMask = newMask.getMaskAsBinaryArray(); assertEquals(mask.getX(), newMask.getX(), Double.MIN_VALUE); @@ -381,7 +382,7 @@ void convertPoint() { roiList.add(ijPoint); ROI roi = ROIWrapper.fromImageJ(roiList).get(0); - Point newPoint = roi.getShapes().getElementsOf(Point.class).get(0); + Point newPoint = getElementsOf(roi.getShapes(), Point.class).get(0); assertEquals(point.getX(), newPoint.getX(), Double.MIN_VALUE); assertEquals(point.getY(), newPoint.getY(), Double.MIN_VALUE); @@ -410,7 +411,7 @@ void convertText() { roiList.add(ijPoint); ROI roi = ROIWrapper.fromImageJ(roiList).get(0); - Text newText = roi.getShapes().getElementsOf(Text.class).get(0); + Text newText = getElementsOf(roi.getShapes(), Text.class).get(0); assertEquals(text.getX(), newText.getX(), Double.MIN_VALUE); assertEquals(text.getY(), newText.getY(), Double.MIN_VALUE); @@ -469,7 +470,7 @@ void convertPolygon() { roiList.add(ijPolygon); ROI roi = ROIWrapper.fromImageJ(roiList).get(0); - Polygon newPolygon = roi.getShapes().getElementsOf(Polygon.class).get(0); + Polygon newPolygon = getElementsOf(roi.getShapes(), Polygon.class).get(0); assertEquals(polygon.getPoints(), newPolygon.getPoints()); assertEquals(polygon.getC(), newPolygon.getC()); @@ -500,7 +501,7 @@ void convertPolyline() { roiList.add(ijPolyline); ROI roi = ROIWrapper.fromImageJ(roiList).get(0); - Polyline newPolyline = roi.getShapes().getElementsOf(Polyline.class).get(0); + Polyline newPolyline = getElementsOf(roi.getShapes(), Polyline.class).get(0); assertEquals(polyline.getPoints(), newPolyline.getPoints()); assertEquals(polyline.getC(), newPolyline.getC()); @@ -525,7 +526,7 @@ void convertRectangleWithCStack() { roiList.add(ijRoi); ROI roi = ROIWrapper.fromImageJ(roiList, null).get(0); - Rectangle newRectangle = roi.getShapes().getElementsOf(Rectangle.class).get(0); + Rectangle newRectangle = getElementsOf(roi.getShapes(), Rectangle.class).get(0); assertEquals(pos - 1, newRectangle.getC()); assertEquals(0, newRectangle.getZ()); @@ -549,7 +550,7 @@ void convertRectangleWithZStack() { roiList.add(ijRoi); ROI roi = ROIWrapper.fromImageJ(roiList, null).get(0); - Rectangle newRectangle = roi.getShapes().getElementsOf(Rectangle.class).get(0); + Rectangle newRectangle = getElementsOf(roi.getShapes(), Rectangle.class).get(0); assertEquals(0, newRectangle.getC()); assertEquals(pos - 1, newRectangle.getZ()); @@ -573,7 +574,7 @@ void convertRectangleWithTStack() { roiList.add(ijRoi); ROI roi = ROIWrapper.fromImageJ(roiList, null).get(0); - Rectangle newRectangle = roi.getShapes().getElementsOf(Rectangle.class).get(0); + Rectangle newRectangle = getElementsOf(roi.getShapes(), Rectangle.class).get(0); assertEquals(0, newRectangle.getC()); assertEquals(0, newRectangle.getZ()); diff --git a/src/test/java/fr/igred/omero/roi/ROITest.java b/src/test/java/fr/igred/omero/roi/ROITest.java index e795b14d..6665c523 100644 --- a/src/test/java/fr/igred/omero/roi/ROITest.java +++ b/src/test/java/fr/igred/omero/roi/ROITest.java @@ -28,6 +28,7 @@ import java.util.Collection; import java.util.List; +import static fr.igred.omero.RemoteObject.getElementsOf; import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -264,15 +265,15 @@ void testROIAllShapes() throws Exception { image.saveROIs(client, roiWrapper); List rois = image.getROIs(client); - ShapeList shapes = rois.get(0).getShapes(); - List points = shapes.getElementsOf(Point.class); - List texts = shapes.getElementsOf(Text.class); - List rectangles = shapes.getElementsOf(Rectangle.class); - List masks = shapes.getElementsOf(Mask.class); - List ellipses = shapes.getElementsOf(Ellipse.class); - List lines = shapes.getElementsOf(Line.class); - List polylines = shapes.getElementsOf(Polyline.class); - List polygons = shapes.getElementsOf(Polygon.class); + List shapes = rois.get(0).getShapes(); + List points = getElementsOf(shapes, Point.class); + List texts = getElementsOf(shapes, Text.class); + List rectangles = getElementsOf(shapes, Rectangle.class); + List masks = getElementsOf(shapes, Mask.class); + List ellipses = getElementsOf(shapes, Ellipse.class); + List lines = getElementsOf(shapes, Line.class); + List polylines = getElementsOf(shapes, Polyline.class); + List polygons = getElementsOf(shapes, Polygon.class); assertEquals(1, rois.size()); assertEquals(8, shapes.size()); diff --git a/src/test/java/fr/igred/omero/util/WrapperTest.java b/src/test/java/fr/igred/omero/util/WrapperTest.java index 47ccd230..bd8d4ef2 100644 --- a/src/test/java/fr/igred/omero/util/WrapperTest.java +++ b/src/test/java/fr/igred/omero/util/WrapperTest.java @@ -20,7 +20,6 @@ import fr.igred.omero.BasicTest; import fr.igred.omero.ObjectWrapper; -import fr.igred.omero.annotations.AnnotationList; import fr.igred.omero.annotations.FileAnnotationWrapper; import fr.igred.omero.annotations.MapAnnotationWrapper; import fr.igred.omero.annotations.RatingAnnotationWrapper; @@ -92,8 +91,6 @@ import java.util.stream.Stream; import static fr.igred.omero.util.Wrapper.wrap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Named.named; @@ -199,16 +196,6 @@ void testWrapWrongAnnotationData() { } - @Test - void testAddWrongAnnotationDataToAnnotationList() { - AnnotationList annotations = new AnnotationList(); - - boolean added = annotations.add(new WrongAnnotationData()); - assertFalse(added); - assertEquals(0, annotations.size()); - } - - private static class WrongDataObject extends DataObject { WrongDataObject() {