Class ObjectMaskStream

Object
ObjectMaskStream

public final class ObjectMaskStream extends Object
A custom "stream" like class for various functional-programming operations on ObjectCollection
Author:
Owen Feehan
  • Constructor Details

  • Method Details

    • map

      public <E extends Exception> ObjectCollection map(CheckedFunction<ObjectMask,ObjectMask,E> mapFunction) throws E
      Creates a new ObjectCollection 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

      public ObjectCollection mapBoundingBoxPreserveExtent(UnaryOperator<BoundingBox> mapFunction)
      Creates a new ObjectCollection 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

      public ObjectCollection mapBoundingBoxChangeExtent(BoundingBox boxToAssign)
      Creates a new ObjectCollection 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,E> mapFunction) throws E
      Creates a new List after mapping each item to another type.

      This is an immutable operation.

      Type Parameters:
      T - destination type for the mapping
      E - 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>,E> mapFunction) throws E
      Creates a new List after mapping each item to another (optional) type

      Items are only included if the output type is not-empty()

      This is an immutable operation.

      Type Parameters:
      T - destination type for the mapping
      E - 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,E> mapFunction) throws E
      Creates a new SortedSet after mapping each item to another type.

      This is an immutable operation.

      Type Parameters:
      T - destination type for the mapping
      E - 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

      public ObjectCollection flatMap(Function<ObjectMask,ObjectCollection> mapFunction)
      Creates a new ObjectCollection 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,E> mapFunction) throws E
      Like a typical flatMap() 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 by mapFunction.
      Parameters:
      throwableClass - the class of E.
      mapFunction - performs flat-mapping.
      Returns:
      a newly created object-collection.
      Throws:
      E - if its thrown by mapFunction.
    • filter

      public ObjectCollection filter(Predicate<ObjectMask> predicate)
      Filters a ObjectCollection to include certain items based on a predicate

      This 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 E
      Filters a ObjectCollection to include certain items based on a predicate

      This is an immutable operation.

      Type Parameters:
      E - an exception that may be thrown by predicate.
      Parameters:
      predicate - iff true object is included, otherwise excluded.
      throwableClass - the class of E.
      Returns:
      a newly created object-collection, a filtered version of all objects.
      Throws:
      E - if the exception is thrown during filtering.
    • filterExclude

      public ObjectCollection filterExclude(Predicate<ObjectMask> predicate)
      Filters a ObjectCollection to exclude certain items based on a predicate

      This 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)
      Parameters:
      predicate - iff true object is included, otherwise excluded
      mapFunction - performs mapping
      Returns:
      a newly created object-collection, a filtered version of all objects, then mapped
    • filterSubset

      public ObjectCollection filterSubset(Predicate<ObjectMask> predicate, Collection<Integer> indices)
      Like filter(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 excluded
      indices - 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)
      Parameters:
      predicate - iff true object is included, otherwise excluded
      indices - which indices of the collection to consider
      Returns:
      a stream of filtered objects
    • anyMatch

      public boolean anyMatch(Predicate<ObjectMask> predicate)
      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

      public Set<ObjectMask> toSet()
      Converts to a HashSet.
      Returns:
      a newly-created set, containing the items in the stream.
    • maxAsInt

      public OptionalInt maxAsInt(ToIntFunction<ObjectMask> function)
      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

      public OptionalInt minAsInt(ToIntFunction<ObjectMask> function)
      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)