public class ObjectIndex<E> extends Object implements Collection<E>
The object index keeps lists of objects segregated by type. The type
hierarchy beneath which each object is classified can be customized through
subclassing (e.g., see PluginIndex
), but by
default, each registered object is added to all type lists with which its
class is compatible. For example, an object of type String
would be
added to the following type lists: String
,
Serializable
, Comparable
, CharSequence
and
Object
. A subsequent request for all objects of type
Comparable
(via a call to get(Class)
) would return a list
that includes the object.
Note that similar to List
, it is possible for the same object to be
added to the index more than once, in which case it will appear on relevant
type lists multiple times.
Note that similar to List
, it is possible for the same object to be
added to the index more than once, in which case it will appear on compatible
type lists multiple times.
Modifier and Type | Field and Description |
---|---|
protected Map<Class<?>,List<E>> |
hoard
"Them as counts counts moren them as dont count."
—Russell Hoban, Riddley Walker |
Constructor and Description |
---|
ObjectIndex(Class<E> baseClass) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E o) |
protected boolean |
add(E o,
boolean batch)
Adds the object to all compatible type lists.
|
protected boolean |
add(E o,
Class<?> type,
boolean batch)
Adds an object to type lists beneath the given type hierarchy.
|
boolean |
addAll(Collection<? extends E> c) |
void |
addLater(LazyObjects<? extends E> c)
Registers objects which will be created lazily as needed.
|
protected boolean |
addToList(E obj,
List<E> list,
boolean batch) |
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
List<E> |
get(Class<?> type)
Gets a list of registered objects compatible with the given type.
|
List<E> |
getAll()
Gets a list of all registered objects.
|
Class<E> |
getBaseClass()
Gets the base class of the items being managed.
|
protected Class<?> |
getType(E o)
Return the type by which to index the object.
|
protected static Class<?>[] |
getTypes(Class<?> type)
Gets a new set containing the type and all its supertypes.
|
boolean |
isEmpty() |
Iterator<E> |
iterator() |
boolean |
remove(Object o) |
protected boolean |
remove(Object o,
boolean batch)
Removes the object from all compatible type lists.
|
protected boolean |
remove(Object o,
Class<?> type,
boolean batch)
Removes an object from type lists beneath the given type hierarchy.
|
boolean |
removeAll(Collection<?> c) |
protected boolean |
removeFromList(Object obj,
List<E> list,
boolean batch) |
boolean |
retainAll(Collection<?> c) |
protected List<E> |
retrieveList(Class<?> type)
Retrieves the type list for the given type, creating it if necessary.
|
protected List<E>[] |
retrieveListsForType(Class<?> type) |
int |
size() |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
equals, hashCode, parallelStream, removeIf, spliterator, stream
public List<E> getAll()
public List<E> get(Class<?> type)
public void addLater(LazyObjects<? extends E> c)
This is useful if creation of the objects is expensive for some reason. In
that case, the object index can wait to actually request and register the
objects until the next accessor method invocation (i.e.,
get(Class)
or getAll()
).
public int size()
size
in interface Collection<E>
public boolean isEmpty()
isEmpty
in interface Collection<E>
public boolean contains(Object o)
contains
in interface Collection<E>
public Object[] toArray()
toArray
in interface Collection<E>
public <T> T[] toArray(T[] a)
toArray
in interface Collection<E>
public boolean add(E o)
add
in interface Collection<E>
public boolean remove(Object o)
remove
in interface Collection<E>
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<E>
public boolean addAll(Collection<? extends E> c)
addAll
in interface Collection<E>
public boolean removeAll(Collection<?> c)
removeAll
in interface Collection<E>
public boolean retainAll(Collection<?> c)
retainAll
in interface Collection<E>
public void clear()
clear
in interface Collection<E>
protected boolean add(E o, boolean batch)
protected boolean remove(Object o, boolean batch)
protected boolean add(E o, Class<?> type, boolean batch)
protected boolean remove(Object o, Class<?> type, boolean batch)
protected static Class<?>[] getTypes(Class<?> type)
Copyright © 2015–2022 SciJava. All rights reserved.