public class ObjectCollection extends Object implements 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.
Constructor and Description |
---|
ObjectCollection(ArrayList<ObjectMask> objects)
Creates with the underlying list.
|
ObjectCollection(java.util.stream.Stream<ObjectMask> stream)
Creates with elements from a stream.
|
Modifier and Type | Method and Description |
---|---|
List<ObjectMask> |
asList()
Exposes the underlying objects as a
ArrayList . |
ObjectCollection |
createSubset(Collection<Integer> indices)
A subset of the collection identified by particular indices.
|
ObjectCollection |
duplicate()
Deep copy, including duplicating
ObjectMask s. |
ObjectCollection |
duplicateShallow()
Shallow copy of objects.
|
boolean |
equals(Object other)
Checks if two collections are equal in a shallow way.
|
boolean |
equalsDeep(ObjectCollection other)
Checks if two collections are equal in a deeper way.
|
ObjectMask |
get(int index)
Get an
ObjectMask at a particular position in the collection. |
BinaryValuesInt |
getFirstBinaryValues()
The
BinaryValuesInt associated with the first object in the collection. |
BinaryValuesByte |
getFirstBinaryValuesByte()
The
BinaryValuesByte associated with the first object in the collection. |
int |
hashCode() |
boolean |
isEmpty()
Whether the collection contains no objects.
|
Iterator<ObjectMask> |
iterator() |
ObjectCollection |
shiftBy(ReadableTuple3i shiftBy)
Shifts the bounding-box of each object by adding to it.
|
int |
size()
The number of objects in the collection.
|
ObjectMaskStream |
stream()
Provides various functional-programming operations on the object-collection.
|
java.util.stream.Stream<ObjectMask> |
streamIndices(Collection<Integer> indices)
Streams only objects at specific indices.
|
java.util.stream.Stream<ObjectMask> |
streamStandardJava()
A stream of object-masks as per Java's standard collections interface.
|
String |
toString()
Default string representation of the collection, one line with each object described by its
center-of-gravity.
|
String |
toString(boolean newlines,
boolean includeIndices)
A string representation of all objects in the collection using their center of gravities (and
optionally indices).
|
forEach, spliterator
public ObjectCollection(ArrayList<ObjectMask> objects)
Note that as objects
will be used internally, it should no used, or especially
changed external to this class.
objects
- the list of objects that will be used internally.public ObjectCollection(java.util.stream.Stream<ObjectMask> stream)
stream
- the stream of objects.public ObjectCollection shiftBy(ReadableTuple3i shiftBy)
i.e. adds a vector to the corner position.
This is an immutable operation.
shiftBy
- what to add to the corner position.public boolean equals(Object other)
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.
public boolean equalsDeep(ObjectCollection other)
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.
other
- the collection to test equality with.other
, as above.public ObjectMask get(int index)
ObjectMask
at a particular position in the collection.index
- the index the object is located at.IndexOutOfBoundsException
- if the index is out of range.public boolean isEmpty()
public Iterator<ObjectMask> iterator()
iterator
in interface Iterable<ObjectMask>
public int size()
public String toString(boolean newlines, boolean includeIndices)
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.public String toString()
public BinaryValuesByte getFirstBinaryValuesByte()
BinaryValuesByte
associated with the first object in the collection.IndexOutOfBoundsException
- if the collection is empty.public BinaryValuesInt getFirstBinaryValues()
BinaryValuesInt
associated with the first object in the collection.IndexOutOfBoundsException
- if the collection is empty.public ObjectCollection duplicate()
ObjectMask
s.public ObjectCollection duplicateShallow()
public ObjectCollection createSubset(Collection<Integer> indices)
This is an immutable operation.
indices
- index of each element to keep in new collection.public List<ObjectMask> asList()
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.
ObjectMask
s in this collection.public ObjectMaskStream stream()
public java.util.stream.Stream<ObjectMask> streamStandardJava()
public java.util.stream.Stream<ObjectMask> streamIndices(Collection<Integer> indices)
indices
- indices of objects to place in the stream.indices
.Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.