public interface ManyAssociation<T> extends Iterable<T>, AbstractAssociation
Duplication of entities (defined as Identity equality) is allowed and for each add, there will be
an additional item in the collection/iterator. If de-duplication is requested, see toSet()
method.
Modifier and Type | Method and Description |
---|---|
boolean |
add(int index,
T entity)
Adds an entity reference representing the given entity to the
index slot of this collection. |
boolean |
add(T entity)
Adds an entity reference representing the given entity to the end of this collection.
|
boolean |
clear()
Clear all entities from this
ManyAssociation . |
boolean |
contains(T entity)
Check is the entity is part of this
ManyAssociation . |
int |
count()
Returns the number of references in this association.
|
T |
get(int index)
Fetch the entity refrence at the given index and fetch the entity from the entity store.
|
Stream<EntityReference> |
references()
Returns a stream of the references to the associated entities.
|
boolean |
remove(T entity)
Removes the given entity from this
ManyAssociation . |
List<T> |
toList()
Fetches all entities represented by entity references in this collection and returns a List of such
entities.
|
Set<T> |
toSet()
Fetches all entities represented by entity references in this collection and returns a Set of such
entities.
|
forEach, iterator, spliterator
boolean contains(T entity)
ManyAssociation
.entity
- The entity to be checking for.Identity
as the given
entity , otherwise false.boolean add(int index, T entity)
index
slot of this collection.
index=0
represents the beginning of the collection and if the index
is equal or larger
than the length of the collection, the entity reference will be added to the end.
entity
- The entity whose entity reference is to be added to this collection.index
- the position for the entity to be inserted at, starting at 0. If index is larger than number
of references present, then it will be added to the end. If index is smaller than 0, then it
will be added at the beginning, position 0.boolean add(T entity)
entity
- The entity whose entity reference is to be added to this collection.boolean remove(T entity)
ManyAssociation
.
The entity reference representing the given entity is removed from this collection.
entity
- The entity reference to be removed.boolean clear()
ManyAssociation
.
All entity references present is removed from this collection.
T get(int index)
index
- The index location in the collection of the entity reference to be fetched.int count()
List<T> toList()
Multiple references to the same entity will be present multiple times in the List, unlike toSet()
.
The order in which the entities were added to this collection is preserved.
Set<T> toSet()
Multiple references to the same entity will NOT be present, unlike toList()
. Sets are defined
to only contain any particular object once. Order is not preserved.
Stream<EntityReference> references()