Skip to content

Commit

Permalink
Remove AnnotationList and ShapeList
Browse files Browse the repository at this point in the history
  • Loading branch information
ppouchin committed Dec 1, 2024
1 parent f9465e7 commit 2963d59
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 288 deletions.
17 changes: 6 additions & 11 deletions src/main/java/fr/igred/omero/Annotatable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,8 +68,10 @@ public interface Annotatable extends RemoteObject {
* @throws AccessException Cannot access data.
* @throws ExecutionException A Facility can't be retrieved or instantiated.
*/
<A extends Annotation> boolean isLinked(Browser browser, A annotation)
throws ServiceException, AccessException, ExecutionException;
default <A extends Annotation> boolean isLinked(Browser browser, A annotation)
throws ServiceException, AccessException, ExecutionException {
return getAnnotations(browser).stream().anyMatch(a -> a.getId() == annotation.getId());
}


/**
Expand Down Expand Up @@ -606,14 +607,8 @@ default List<AnnotationData> 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> annotationData = getAnnotationData(browser);

AnnotationList annotations = new AnnotationList(annotationData.size());
annotationData.forEach(annotations::add);
return annotations;
}
List<Annotation> getAnnotations(Browser browser)
throws AccessException, ServiceException, ExecutionException;


/**
Expand Down
39 changes: 19 additions & 20 deletions src/main/java/fr/igred/omero/AnnotatableWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <A> 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 <A extends Annotation> 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.
*
Expand Down Expand Up @@ -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<Annotation> getAnnotations(Browser browser)
throws AccessException, ServiceException, ExecutionException {
return wrap(getAnnotationData(browser), Wrapper::wrap);
}

}
40 changes: 30 additions & 10 deletions src/main/java/fr/igred/omero/RemoteObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand All @@ -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 <U> Subclass of RemoteObject.
* @param <V> Subclass of U.
*
* @return See above.
*/
static <U extends RemoteObject, V extends U> List<V> getElementsOf(Collection<? extends U> collection,
Class<? extends V> clazz) {
return collection.stream()
.filter(clazz::isInstance)
.map(clazz::cast)
.collect(toList());
}


/**
* Only keeps objects with different IDs in a collection.
*
Expand All @@ -52,28 +72,28 @@ static <T extends RemoteObject> List<T> distinct(Collection<? extends T> 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());
}


/**
* Flattens a collection of collections and only keeps objects with different IDs.
*
* @param lists A collection of objects collections.
* @param <U> The objects type.
* @param <T> The objects type.
*
* @return Distinct objects list, sorted by ID.
*/
static <U extends RemoteObject>
List<U> flatten(Collection<? extends Collection<? extends U>> lists) {
static <T extends RemoteObject>
List<T> flatten(Collection<? extends Collection<? extends T>> 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());
}


Expand Down
90 changes: 0 additions & 90 deletions src/main/java/fr/igred/omero/annotations/AnnotationList.java

This file was deleted.

4 changes: 4 additions & 0 deletions src/main/java/fr/igred/omero/core/PlaneInfoWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import omero.model.Time;


/**
* Class containing a PlaneInfoData object.
* <p> Wraps function calls to the PlaneInfoData contained.
*/
public class PlaneInfoWrapper extends ObjectWrapper<PlaneInfoData> implements PlaneInfo {

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/igred/omero/roi/ROI.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ default void addShapes(Iterable<? extends Shape> shapes) {
*
* @return list of shape contained in the ROIData.
*/
ShapeList getShapes();
List<Shape> getShapes();


/**
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/fr/igred/omero/roi/ROIWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -222,13 +222,8 @@ public void addShape(Shape shape) {
* @return list of shape contained in the ROIData.
*/
@Override
public ShapeList getShapes() {
List<ShapeData> shapeData = data.getShapes();
ShapeList shapes = new ShapeList(shapeData.size());
shapeData.stream()
.sorted(Comparator.comparing(ShapeData::getId))
.forEachOrdered(shapes::add);
return shapes;
public List<Shape> getShapes() {
return wrap(data.getShapes(), Wrapper::wrap);
}


Expand Down Expand Up @@ -298,7 +293,7 @@ public List<ij.gui.Roi> toImageJ(String property) {
String ijNameProperty = ROI.ijNameProperty(property);
String roiID = String.valueOf(getId());

ShapeList shapes = getShapes();
List<Shape> shapes = getShapes();

Map<String, List<Shape>> sameSlice = shapes.stream()
.collect(groupingBy(Shape::getCZT,
Expand Down
Loading

0 comments on commit 2963d59

Please sign in to comment.