public class EntityCollection extends AbstractCollection<Entity> implements Serializable, Describable
A collection of entities of a single type. This collection augments the Collection
interface with logic for different kinds of (possibly optimized) entity searches.
Modifier and Type | Method and Description |
---|---|
void |
describeTo(DescriptionWriter writer)
Write this class’s description to a sink.
|
<T> List<Entity> |
find(Attribute<T> attr)
Find entities with an attribute.
|
List<Entity> |
find(String name,
Object value)
Find entities by attribute.
|
<T> List<Entity> |
find(TypedName<T> name,
T value)
Find entities by attribute.
|
EntityType |
getType()
Get the type of entity stored in this collection.
|
LongSet |
idSet() |
Iterator<Entity> |
iterator() |
Entity |
lookup(long id)
Look up an entity by ID.
|
static EntityCollectionBuilder |
newBuilder(EntityType type)
Create a new entity collection builder.
|
int |
size() |
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
equals, hashCode, parallelStream, removeIf, spliterator, stream
public static EntityCollectionBuilder newBuilder(EntityType type)
Create a new entity collection builder.
public EntityType getType()
Get the type of entity stored in this collection.
public LongSet idSet()
@Nullable public Entity lookup(long id)
Look up an entity by ID.
id
- The entity ID.null
if no such entity exists.@Nonnull public <T> List<Entity> find(TypedName<T> name, T value)
Find entities by attribute.
name
- The attribute name.value
- The attribute value.name
has value value
.@Nonnull public <T> List<Entity> find(Attribute<T> attr)
Find entities with an attribute.
attr
- The attribute to look for.T
- The attribute type.@Nonnull public List<Entity> find(String name, Object value)
Find entities by attribute.
name
- The attribute name.value
- The attribute value.name
has value value
.@Nonnull public Iterator<Entity> iterator()
iterator
in interface Iterable<Entity>
iterator
in interface Collection<Entity>
iterator
in class AbstractCollection<Entity>
public int size()
size
in interface Collection<Entity>
size
in class AbstractCollection<Entity>
public void describeTo(DescriptionWriter writer)
Describable
Write this class’s description to a sink. Anything relevant to this object’s identity should be digested; the idea is that, barring hash collisions, two objects with the same digest are equivalent. Used for things like deterministically generating cache file names.
describeTo
in interface Describable
writer
- The description writer to use.