Class ObjectCollectionFactory

Object
ObjectCollectionFactory

public class ObjectCollectionFactory extends Object
Creates ObjectCollection using various utility and helper methods.
Author:
Owen Feehan
  • Method Details

    • empty

      public static ObjectCollection empty()
      Creates a newly created object-collection that is empty.
      Returns:
      a newly-created empty object collection.
    • of

      @SafeVarargs public static ObjectCollection of(ObjectMask... object)
      Creates a new collection with elements from the parameter-list.
      Parameters:
      object - object-mask to add to collection.
      Returns:
      the newly-created collection, reusing object.
    • of

      @SafeVarargs public static ObjectCollection of(ObjectCollection... collection)
      Creates a new collection with elements copied from existing collections.
      Parameters:
      collection - existing collections to copy from.
      Returns:
      the newly-created collection, reusing the objects from objects.
    • of

      @SafeVarargs public static ObjectCollection of(Optional<ObjectCollection>... collections)
      Creates a new collection with elements copied from existing collections, if they exist.
      Parameters:
      collections - existing collections to copy from.
      Returns:
      the newly-created collection, reusing the objects from objects.
    • of

      @SafeVarargs public static ObjectCollection of(Collection<ObjectMask>... collections)
      Creates a new collection with elements copied from existing collections.
      Parameters:
      collections - one or more collections to add items from.
      Returns:
      a newly created ObjectCollection, reusing the objects in collections.
    • mapFrom

      public static <T> ObjectCollection mapFrom(Iterable<T> iterable, Function<T,ObjectMask> mapFunction)
      Creates a new collection by mapping an Iterable to ObjectMask.
      Type Parameters:
      T - type that will be mapped to ObjectCollection.
      Parameters:
      iterable - source of entities to be mapped.
      mapFunction - function for mapping.
      Returns:
      a newly created ObjectCollection.
    • mapFrom

      public static <T, E extends Exception> ObjectCollection mapFrom(Iterable<T> iterable, Class<? extends E> throwableClass, CheckedFunction<T,ObjectMask,E> mapFunction) throws E
      Creates a new collection by mapping an Iterable to ObjectMask.
      Type Parameters:
      T - type that will be mapped to ObjectCollection.
      E - exception-type that can be thrown during mapping.
      Parameters:
      iterable - source of entities to be mapped.
      throwableClass - the class of the exception that might be thrown during mapping.
      mapFunction - function for mapping.
      Returns:
      a newly created ObjectCollection.
      Throws:
      E - exception if it occurs during mapping.
    • mapFromOptional

      public static <T> ObjectCollection mapFromOptional(Iterable<T> iterable, Function<T,Optional<ObjectMask>> mapFunction)
      Creates a new collection by mapping an Iterable to Optional.

      The object is only included in the outgoing collection if Optional.isPresent().

      Type Parameters:
      T - type that will be mapped to ObjectCollection.
      Parameters:
      iterable - iterable to be mapped.
      mapFunction - function for mapping.
      Returns:
      a newly created ObjectCollection.
    • mapFromOptional

      public static <T, E extends Exception> ObjectCollection mapFromOptional(Iterable<T> iterable, Class<? extends Exception> throwableClass, CheckedFunction<T,Optional<ObjectMask>,E> mapFunction) throws E
      Creates a new collection by mapping an Iterable to Optional.

      The object is only included in the outgoing collection if Optional.isPresent().

      Type Parameters:
      T - type that will be mapped to ObjectCollection.
      E - exception-type that can be thrown during mapping.
      Parameters:
      iterable - iterable to be mapped.
      throwableClass - the class of the exception that might be thrown during mapping.
      mapFunction - function for mapping.
      Returns:
      a newly created ObjectCollection.
      Throws:
      E - exception if it occurs during mapping.
    • mapFromOptional

      public static <T> ObjectCollection mapFromOptional(Iterator<T> iterator, Function<T,Optional<ObjectMask>> mapFunction)
      Creates a new collection by mapping an Iterator to Optional.

      The object is only included in the outgoing collection if Optional.isPresent().

      Type Parameters:
      T - type that will be mapped to ObjectCollection.
      Parameters:
      iterator - to be mapped.
      mapFunction - function for mapping.
      Returns:
      a newly created ObjectCollection.
    • mapFromOptional

      public static <T, E extends Exception> ObjectCollection mapFromOptional(Iterator<T> iterator, Class<? extends Exception> throwableClass, CheckedFunction<T,Optional<ObjectMask>,E> mapFunction) throws E
      Creates a new collection by mapping an Iterator to Optional.

      The object is only included in the outgoing collection if Optional.isPresent().

      Type Parameters:
      T - type that will be mapped to ObjectCollection.
      E - exception-type that can be thrown during mapping.
      Parameters:
      iterator - to be mapped.
      throwableClass - the class of the exception that might be thrown during mapping.
      mapFunction - function for mapping.
      Returns:
      a newly created ObjectCollection.
      Throws:
      E - exception if it occurs during mapping.
    • of

      Creates a new collection with elements from the parameter-list of BinaryVoxels converting the voxels in their entirety to an object-mask at the origin.
      Parameters:
      masks - object-mask to add to collection.
      Returns:
      a newly created ObjectCollection.
    • fromSet

      public static ObjectCollection fromSet(Set<ObjectMask> set)
      Creates a new collection from a set of ObjectMask.
      Parameters:
      set - set.
      Returns:
      the newly created collection.
    • fromRepeated

      public static ObjectCollection fromRepeated(int repeats, Supplier<ObjectMask> createObjectMask)
      Creates a new collection by repeatedly calling a function to create a single ObjectMask.
      Parameters:
      repeats - the number of objects created.
      createObjectMask - creates a new object-mask.
      Returns:
      a newly created ObjectCollection.
    • mapFromRange

      public static ObjectCollection mapFromRange(int startInclusive, int endExclusive, IntFunction<ObjectMask> mapFunction)
      Creates a new collection by mapping integers (from a range) each to a ObjectMask.
      Parameters:
      startInclusive - start index for the integer range (inclusive).
      endExclusive - end index for the integer range (exclusive).
      mapFunction - function for mapping.
      Returns:
      a newly created ObjectCollection.
    • mapFromRange

      public static <E extends Exception> ObjectCollection mapFromRange(int startInclusive, int endExclusive, Class<? extends Exception> throwableClass, CheckedIntFunction<ObjectMask,E> mapFunction) throws E
      Creates a new collection by mapping integers (from a range) each to a ObjectMask.
      Parameters:
      startInclusive - start index for the integer range (inclusive).
      endExclusive - end index for the integer range (exclusive).
      throwableClass - the class of the exception that might be thrown during mapping.
      mapFunction - function for mapping.
      Returns:
      a newly created ObjectCollection.
      Throws:
      E - if the exception is thrown during mapping.
    • flatMapFromRange

      public static ObjectCollection flatMapFromRange(int startInclusive, int endExclusive, IntFunction<ObjectCollection> mapFunction)
      Creates a new collection by flat-mapping integers (from a range) each to a ObjectCollection.
      Parameters:
      startInclusive - start index for the integer range (inclusive).
      endExclusive - end index for the integer range (exclusive).
      mapFunction - function for flat-mapping.
      Returns:
      a newly created ObjectCollection.
    • flatMapFromRange

      public static <E extends Exception> ObjectCollection flatMapFromRange(int startInclusive, int endExclusive, Class<? extends Exception> throwableClass, CheckedIntFunction<ObjectCollection,E> mapFunction) throws E
      Creates a new collection by flat-mapping integers (from a range) each to a ObjectCollection.
      Parameters:
      startInclusive - start index for the integer range (inclusive).
      endExclusive - end index for the integer range (exclusive).
      throwableClass - the class of the exception that might be thrown during mapping.
      mapFunction - function for flat-mapping.
      Returns:
      a newly created ObjectCollection.
      Throws:
      E - exception if it occurs during mapping.
    • filterAndMapFrom

      public static <T> ObjectCollection filterAndMapFrom(Collection<T> collection, Predicate<T> predicate, Function<T,ObjectMask> mapFunction)
      Creates a new collection by filtering an iterable and then mapping it to ObjectMask.
      Type Parameters:
      T - type that will be mapped to ObjectMask.
      Parameters:
      collection - incoming collection to be mapped.
      predicate - only elements from the iterable that satisfy this predicate are added.
      mapFunction - function for mapping.
      Returns:
      a newly created ObjectCollection.
    • filterAndMapFrom

      public static <T, E extends Exception> ObjectCollection filterAndMapFrom(Collection<T> collection, Predicate<T> predicate, Class<? extends E> throwableClass, CheckedFunction<T,ObjectMask,E> mapFunction) throws E
      Creates a new collection by filtering an iterable and then mapping it to ObjectMask.
      Type Parameters:
      T - type that will be mapped to ObjectMask.
      E - exception-type that may be thrown during mapping.
      Parameters:
      collection - incoming collection to be mapped.
      predicate - only elements from the iterable that satisfy this predicate are added.
      throwableClass - the class of E.
      mapFunction - function for mapping.
      Returns:
      a newly created ObjectCollection.
      Throws:
      E - if thrown by mapFunction
    • filterAndMapWithIndexFrom

      public static <T, E extends Exception> ObjectCollection filterAndMapWithIndexFrom(List<T> list, Predicate<T> predicate, Class<? extends E> throwableClass, CheckedBiFunction<T,Integer,ObjectMask,E> mapFunctionWithIndex) throws E
      Creates a new collection by filtering a list and then mapping from it to ObjectMask.
      Type Parameters:
      T - type that will be mapped to ObjectCollection.
      E - exception that be thrown during mapping.
      Parameters:
      list - incoming list to be mapped.
      predicate - only elements from the list that satisfy this predicate are added.
      throwableClass - the class of the exception that might be thrown during mapping.
      mapFunctionWithIndex - function for mapping, also including an index (the original position in the bounding-box).
      Returns:
      a newly created ObjectCollection.
      Throws:
      E - if an exception is thrown during mapping.
    • flatMapFrom

      public static <T> ObjectCollection flatMapFrom(Collection<T> collection, Function<T,ObjectCollection> mapFunction)
      Creates a new collection by flat-mapping an incoming stream to ObjectCollection.
      Type Parameters:
      T - type that will be flatMapped to ObjectCollection.
      Parameters:
      collection - incoming collection to be flat-mapped.
      mapFunction - function for mapping.
      Returns:
      a newly created ObjectCollection.
    • flatMapFrom

      public static <T, E extends Exception> ObjectCollection flatMapFrom(Stream<T> stream, Class<? extends Exception> throwableClass, CheckedFunction<T,ObjectCollection,E> mapFunction) throws E
      Creates a new collection by flat-mapping an incoming stream to ObjectCollection and rethrowing any exception during mapping.
      Type Parameters:
      T - type that will be flatMapped to ObjectCollection.
      Parameters:
      stream - incoming stream to be flat-mapped.
      throwableClass - the class of the exception that might be thrown during mapping.
      mapFunction - function for flat-mapping.
      Returns:
      a newly created ObjectCollection.
      Throws:
      E - exception of it occurs during mapping.
    • flatMapFromStream

      public static <T, E extends Exception> ObjectCollection flatMapFromStream(Stream<T> stream, Class<? extends Exception> throwableClass, CheckedFunction<T,Stream<ObjectMask>,E> mapFunction) throws E
      Creates a new collection by flat-mapping an incoming stream to ObjectCollection and rethrowing any exception during mapping.
      Type Parameters:
      T - type that will be flatMapped to ObjectCollection.
      Parameters:
      stream - incoming stream to be flat-mapped.
      throwableClass - the class of the exception that might be thrown during mapping.
      mapFunction - function for flat-mapping.
      Returns:
      a newly created ObjectCollection.
      Throws:
      E - exception of it occurs during mapping.
    • flatMapFromCollection

      public static <T, E extends Exception> ObjectCollection flatMapFromCollection(Stream<T> stream, Class<? extends Exception> throwableClass, CheckedFunction<T,Stream<? extends ObjectMask>,E> mapFunction) throws E
      Creates a new ObjectCollection by flatMapping an incoming stream to Collection<ObjectMask> and rethrowing any exception during mapping.
      Type Parameters:
      T - type that will be flatMapped to ObjectCollection.
      Parameters:
      stream - incoming stream to be flat-mapped.
      throwableClass - the class of the exception that might be thrown during mapping.
      mapFunction - function for flat-mapping.
      Returns:
      a newly created ObjectCollection.
      Throws:
      E - exception of it occurs during mapping.