Class ObjectMaskStream
ObjectCollection
- Author:
- Owen Feehan
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
anyMatch
(Predicate<ObjectMask> predicate) Does the predicate evaluate to true on any object in the collection?filter
(Predicate<ObjectMask> predicate) Filters aObjectCollection
to include certain items based on a predicate<E extends Exception>
ObjectCollectionfilter
(CheckedPredicate<ObjectMask, E> predicate, Class<? extends Exception> throwableClass) Filters aObjectCollection
to include certain items based on a predicatefilterAndMap
(Predicate<ObjectMask> predicate, UnaryOperator<ObjectMask> mapFunction) filterExclude
(Predicate<ObjectMask> predicate) Filters aObjectCollection
to exclude certain items based on a predicatefilterSubset
(Predicate<ObjectMask> predicate, Collection<Integer> indices) Likefilter(java.util.function.Predicate<org.anchoranalysis.image.voxel.object.ObjectMask>)
but only operates on certain indices of the collection.filterSubsetStream
(Predicate<ObjectMask> predicate, Collection<Integer> indices) LikefilterSubset(java.util.function.Predicate<org.anchoranalysis.image.voxel.object.ObjectMask>, java.util.Collection<java.lang.Integer>)
but returns a stream rather than aObjectCollection
.<E extends Exception>
ObjectCollectionflatMap
(Class<? extends Exception> throwableClass, CheckedFunction<ObjectMask, ObjectCollection, E> mapFunction) Like a typicalflatMap()
operation but accepts a mapping function that throws a checked exception.flatMap
(Function<ObjectMask, ObjectCollection> mapFunction) Creates a newObjectCollection
after mapping each item to several others.<E extends Exception>
ObjectCollectionmap
(CheckedFunction<ObjectMask, ObjectMask, E> mapFunction) Creates a newObjectCollection
after mapping each item to another.mapBoundingBoxChangeExtent
(BoundingBox boxToAssign) Creates a newObjectCollection
after mapping the bounding-box on each object (while maybe changing the extent).mapBoundingBoxPreserveExtent
(UnaryOperator<BoundingBox> mapFunction) Creates a newObjectCollection
after mapping the bounding-box on each object (whose extent should remain unchanged).mapToList
(CheckedFunction<ObjectMask, T, E> mapFunction) Creates a newList
after mapping each item to another type.mapToListOptional
(CheckedFunction<ObjectMask, Optional<T>, E> mapFunction) Creates a newList
after mapping each item to another (optional) typemapToSortedSet
(CheckedFunction<ObjectMask, T, E> mapFunction) Creates a newSortedSet
after mapping each item to another type.maxAsInt
(ToIntFunction<ObjectMask> function) Finds the maximum value of a function applied to each object in the collection.minAsInt
(ToIntFunction<ObjectMask> function) Finds the minimum value of a function applied to each object in the collection.toSet()
Converts to aHashSet
.
-
Constructor Details
-
ObjectMaskStream
-
-
Method Details
-
map
public <E extends Exception> ObjectCollection map(CheckedFunction<ObjectMask, ObjectMask, throws EE> mapFunction) Creates a newObjectCollection
after mapping each item to another.This is an immutable operation.
- Type Parameters:
E
- exception-type that can occur during mapping- Parameters:
mapFunction
- performs mapping- Returns:
- a newly created object-collection
- Throws:
E
- if an exception is thrown by the mapping function.
-
mapBoundingBoxPreserveExtent
Creates a newObjectCollection
after mapping the bounding-box on each object (whose extent should remain unchanged).See
ObjectMask.mapBoundingBoxPreserveExtent(UnaryOperator)
for details on the mapping.This is an immutable operation.
- Parameters:
mapFunction
- maps the bounding-box to a new bounding-box- Returns:
- a newly created object-collection
-
mapBoundingBoxChangeExtent
Creates a newObjectCollection
after mapping the bounding-box on each object (while maybe changing the extent).See
ObjectMask.mapBoundingBoxChangeExtent(org.anchoranalysis.spatial.box.BoundingBox)
for details on the mapping.This is an immutable operation.
Precondition: the new bounding-box's extent must be greater than or equal to the existing extent in all dimensions.
- Parameters:
boxToAssign
- the bounding box to assign to the newly created object- Returns:
- a newly created object-collection
-
mapToList
public <T,E extends Exception> List<T> mapToList(CheckedFunction<ObjectMask, T, throws EE> mapFunction) Creates a newList
after mapping each item to another type.This is an immutable operation.
- Type Parameters:
T
- destination type for the mappingE
- exception that can be thrown during mapping- Parameters:
mapFunction
- performs mapping- Returns:
- a newly created list contained the mapped objects
- Throws:
E
- if an exception occurs during mapping
-
mapToListOptional
public <T,E extends Exception> List<T> mapToListOptional(CheckedFunction<ObjectMask, Optional<T>, throws EE> mapFunction) Creates a newList
after mapping each item to another (optional) typeItems are only included if the output type is not-empty()
This is an immutable operation.
- Type Parameters:
T
- destination type for the mappingE
- exception that can be thrown during mapping- Parameters:
mapFunction
- performs mapping- Returns:
- a newly created list contained the mapped objects (which aren't Optional.empty())
- Throws:
E
- if an exception occurs during mapping
-
mapToSortedSet
public <T,E extends Exception> SortedSet<T> mapToSortedSet(CheckedFunction<ObjectMask, T, throws EE> mapFunction) Creates a newSortedSet
after mapping each item to another type.This is an immutable operation.
- Type Parameters:
T
- destination type for the mappingE
- exception that can be thrown during mapping- Parameters:
mapFunction
- performs mapping- Returns:
- a newly created tree-set contained the mapped objects
- Throws:
E
- if an exception occurs during mapping
-
flatMap
Creates a newObjectCollection
after mapping each item to several others.This is an immutable operation.
- Parameters:
mapFunction
- performs flat-mapping- Returns:
- a newly created object-collection
-
flatMap
public <E extends Exception> ObjectCollection flatMap(Class<? extends Exception> throwableClass, CheckedFunction<ObjectMask, ObjectCollection, throws EE> mapFunction) Like a typicalflatMap()
operation but accepts a mapping function that throws a checked exception.This is an immutable operation.
- Type Parameters:
E
- exception-type that can be thrown bymapFunction
.- Parameters:
throwableClass
- the class ofE
.mapFunction
- performs flat-mapping.- Returns:
- a newly created object-collection.
- Throws:
E
- if its thrown bymapFunction
.
-
filter
Filters aObjectCollection
to include certain items based on a predicateThis is an immutable operation.
- Parameters:
predicate
- iff true object is included, otherwise excluded.- Returns:
- a newly created object-collection, a filtered version of all objects.
-
filter
public <E extends Exception> ObjectCollection filter(CheckedPredicate<ObjectMask, E> predicate, Class<? extends Exception> throwableClass) throws EFilters aObjectCollection
to include certain items based on a predicateThis is an immutable operation.
- Type Parameters:
E
- an exception that may be thrown bypredicate
.- Parameters:
predicate
- iff true object is included, otherwise excluded.throwableClass
- the class ofE
.- Returns:
- a newly created object-collection, a filtered version of all objects.
- Throws:
E
- if the exception is thrown during filtering.
-
filterExclude
Filters aObjectCollection
to exclude certain items based on a predicateThis is an immutable operation.
- Parameters:
predicate
- iff true object is excluded, otherwise included- Returns:
- a newly created object-collection, a filtered version of all objects
-
filterAndMap
public ObjectCollection filterAndMap(Predicate<ObjectMask> predicate, UnaryOperator<ObjectMask> mapFunction) Performs afilter(java.util.function.Predicate<org.anchoranalysis.image.voxel.object.ObjectMask>)
and then amap(org.anchoranalysis.core.functional.checked.CheckedFunction<org.anchoranalysis.image.voxel.object.ObjectMask, org.anchoranalysis.image.voxel.object.ObjectMask, E>)
.This is an immutable operation.
- Parameters:
predicate
- iff true object is included, otherwise excludedmapFunction
- performs mapping- Returns:
- a newly created object-collection, a filtered version of all objects, then mapped
-
filterSubset
Likefilter(java.util.function.Predicate<org.anchoranalysis.image.voxel.object.ObjectMask>)
but only operates on certain indices of the collection.This is an immutable operation
- Parameters:
predicate
- iff true object is included, otherwise excludedindices
- which indices of the collection to consider- Returns:
- a newly created object-collection, a filtered version of particular elements
-
filterSubsetStream
public Stream<ObjectMask> filterSubsetStream(Predicate<ObjectMask> predicate, Collection<Integer> indices) LikefilterSubset(java.util.function.Predicate<org.anchoranalysis.image.voxel.object.ObjectMask>, java.util.Collection<java.lang.Integer>)
but returns a stream rather than aObjectCollection
.This is an immutable operation
- Parameters:
predicate
- iff true object is included, otherwise excludedindices
- which indices of the collection to consider- Returns:
- a stream of filtered objects
-
anyMatch
Does the predicate evaluate to true on any object in the collection?- Parameters:
predicate
- evaluates to true or false for a particular object- Returns:
- true if the predicate returns true on ANY one of the contained objects
-
toSet
Converts to aHashSet
.- Returns:
- a newly-created set, containing the items in the stream.
-
maxAsInt
Finds the maximum value of a function applied to each object in the collection.- Parameters:
function
- function to apply- Returns:
- the maximum-int found by applying the function to each object (so long as the collection isn't empty)
-
minAsInt
Finds the minimum value of a function applied to each object in the collection.- Parameters:
function
- function to apply- Returns:
- the minimum-int found by applying the function to each object (so long as the collection isn't empty)
-