Class ObjectCollection
- All Implemented Interfaces:
Iterable<ObjectMask>
ObjectMask
s.
The class itself contains only immutable methods, although the ObjectMask
s 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 Summary
ConstructorsConstructorDescriptionObjectCollection
(ArrayList<ObjectMask> objects) Creates with the underlying list.ObjectCollection
(Stream<ObjectMask> stream) Creates with elements from a stream. -
Method Summary
Modifier and TypeMethodDescriptionasList()
Exposes the underlying objects as aArrayList
.createSubset
(Collection<Integer> indices) A subset of the collection identified by particular indices.Deep copy, including duplicatingObjectMask
s.Shallow copy of objects.boolean
Checks if two collections are equal in a shallow way.boolean
equalsDeep
(ObjectCollection other) Checks if two collections are equal in a deeper way.get
(int index) Get anObjectMask
at a particular position in the collection.TheBinaryValuesInt
associated with the first object in the collection.TheBinaryValuesByte
associated with the first object in the collection.int
hashCode()
boolean
isEmpty()
Whether the collection contains no objects.iterator()
shiftBy
(ReadableTuple3i shiftBy) Shifts the bounding-box of each object by adding to it.int
size()
The number of objects in the collection.stream()
Provides various functional-programming operations on the object-collection.streamIndices
(Collection<Integer> indices) Streams only objects at specific indices.A stream of object-masks as per Java's standard collections interface.toString()
Default string representation of the collection, one line with each object described by its center-of-gravity.toString
(boolean newlines, boolean includeIndices) A string representation of all objects in the collection using their center of gravities (and optionally indices).Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ObjectCollection
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
Creates with elements from a stream.- Parameters:
stream
- the stream of objects.
-
-
Method Details
-
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
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.
-
equalsDeep
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
Get anObjectMask
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() -
isEmpty
public boolean isEmpty()Whether the collection contains no objects.- Returns:
- true iff the collection contains no objects.
-
iterator
- Specified by:
iterator
in interfaceIterable<ObjectMask>
-
size
public int size()The number of objects in the collection.- Returns:
- the number of elements.
-
toString
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
Default string representation of the collection, one line with each object described by its center-of-gravity. -
getFirstBinaryValuesByte
TheBinaryValuesByte
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
TheBinaryValuesInt
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
Deep copy, including duplicatingObjectMask
s.- Returns:
- the deep-copy.
-
duplicateShallow
Shallow copy of objects.- Returns:
- the deep-copy.
-
createSubset
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
Exposes the underlying objects as aArrayList
.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
ObjectMask
s in this collection.
-
stream
Provides various functional-programming operations on the object-collection.- Returns:
- a stream-like interface of operations.
-
streamStandardJava
A stream of object-masks as per Java's standard collections interface.- Returns:
- the stream.
-
streamIndices
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
.
-