Class ObjectCollection

Object
ObjectCollection
All Implemented Interfaces:
Iterable<ObjectMask>

public class ObjectCollection extends Object implements Iterable<ObjectMask>
A collection of ObjectMasks.

The class itself contains only immutable methods, although the ObjectMasks it contains are themselves mutable.

Note that the asList() method exposes the internal ArrayList used for storing objects, and this may be manipulated in a mutable way.

Author:
Owen Feehan
  • Constructor Details

    • ObjectCollection

      public ObjectCollection(ArrayList<ObjectMask> objects)
      Creates with the underlying list.

      Note that as objects will be used internally, it should no used, or especially changed external to this class.

      Parameters:
      objects - the list of objects that will be used internally.
    • ObjectCollection

      public ObjectCollection(Stream<ObjectMask> stream)
      Creates with elements from a stream.
      Parameters:
      stream - the stream of objects.
  • Method Details

    • shiftBy

      public ObjectCollection shiftBy(ReadableTuple3i shiftBy)
      Shifts the bounding-box of each object by adding to it.

      i.e. adds a vector to the corner position.

      This is an immutable operation.

      Parameters:
      shiftBy - what to add to the corner position.
      Returns:
      newly created object-collection with shifted corner position and identical extent.
    • equals

      public boolean equals(Object other)
      Checks if two collections are equal in a shallow way.

      Specifically, objects are tested to be equal using their object references.

      i.e. they are equal iff they have the same reference.

      This is a cheaper equality check than with equalsDeep(org.anchoranalysis.image.voxel.object.ObjectCollection).

      Both collections must have identical ordering.

      Overrides:
      equals in class Object
    • equalsDeep

      public boolean equalsDeep(ObjectCollection other)
      Checks if two collections are equal in a deeper way.

      Specifically, objects are tested to be equal using a deep byte-by-byte comparison using ObjectMask.equalsDeep(org.anchoranalysis.image.voxel.object.ObjectMask). Their objects do not need to be equal.

      This is more expensive equality check than with equalsDeep(org.anchoranalysis.image.voxel.object.ObjectCollection), but is useful for comparing objects that were instantiated in different places.

      Both collections must have identical ordering.

      Parameters:
      other - the collection to test equality with.
      Returns:
      true iff the the current collection is equal to other, as above.
    • get

      public ObjectMask get(int index)
      Get an ObjectMask at a particular position in the collection.
      Parameters:
      index - the index the object is located at.
      Returns:
      the object.
      Throws:
      IndexOutOfBoundsException - if the index is out of range.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • isEmpty

      public boolean isEmpty()
      Whether the collection contains no objects.
      Returns:
      true iff the collection contains no objects.
    • iterator

      public Iterator<ObjectMask> iterator()
      Specified by:
      iterator in interface Iterable<ObjectMask>
    • size

      public int size()
      The number of objects in the collection.
      Returns:
      the number of elements.
    • toString

      public String toString(boolean newlines, boolean includeIndices)
      A string representation of all objects in the collection using their center of gravities (and optionally indices).
      Parameters:
      newlines - if true a newline separates each item, otherwise a whitespace.
      includeIndices - whether to additionally show the index of each item beside its center of gravity.
      Returns:
      a descriptive string of the collection (beginning and ending with parantheses).
    • toString

      public String toString()
      Default string representation of the collection, one line with each object described by its center-of-gravity.
      Overrides:
      toString in class Object
    • getFirstBinaryValuesByte

      public BinaryValuesByte getFirstBinaryValuesByte()
      The BinaryValuesByte associated with the first object in the collection.
      Returns:
      the binary-values associated with the first object.
      Throws:
      IndexOutOfBoundsException - if the collection is empty.
    • getFirstBinaryValues

      public BinaryValuesInt getFirstBinaryValues()
      The BinaryValuesInt associated with the first object in the collection.
      Returns:
      the binary-values associated with the first object.
      Throws:
      IndexOutOfBoundsException - if the collection is empty.
    • duplicate

      public ObjectCollection duplicate()
      Deep copy, including duplicating ObjectMasks.
      Returns:
      the deep-copy.
    • duplicateShallow

      public ObjectCollection duplicateShallow()
      Shallow copy of objects.
      Returns:
      the deep-copy.
    • createSubset

      public ObjectCollection createSubset(Collection<Integer> indices)
      A subset of the collection identified by particular indices.

      This is an immutable operation.

      Parameters:
      indices - index of each element to keep in new collection.
      Returns:
      newly-created collection with only the indexed elements.
    • asList

      public List<ObjectMask> asList()
      Exposes the underlying objects as a ArrayList.

      It is guaranteed to provide efficient random-access.

      Be careful when manipulating this list, as it is the same list used internally in the object.

      TODO use the method to make it unmodifiable Collections.unmodifiableList after changing calls.

      Returns:
      a list with the ObjectMasks in this collection.
    • stream

      public ObjectMaskStream stream()
      Provides various functional-programming operations on the object-collection.
      Returns:
      a stream-like interface of operations.
    • streamStandardJava

      public Stream<ObjectMask> streamStandardJava()
      A stream of object-masks as per Java's standard collections interface.
      Returns:
      the stream.
    • streamIndices

      public Stream<ObjectMask> streamIndices(Collection<Integer> indices)
      Streams only objects at specific indices.
      Parameters:
      indices - indices of objects to place in the stream.
      Returns:
      the stream containing only the objects whose indices are in indices.