Class ObjectIndex<E>
- java.lang.Object
-
- org.scijava.object.ObjectIndex<E>
-
- All Implemented Interfaces:
Iterable<E>,Collection<E>
- Direct Known Subclasses:
NamedObjectIndex,SortedObjectIndex
public class ObjectIndex<E> extends Object implements Collection<E>
Data structure for managing lists of registered objects.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 typeStringwould be added to the following type lists:String,Serializable,Comparable,CharSequenceandObject. A subsequent request for all objects of typeComparable(via a call toget(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.- Author:
- Curtis Rueden
-
-
Constructor Summary
Constructors Constructor Description ObjectIndex(Class<E> baseClass)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E o)protected booleanadd(E o, boolean batch)Adds the object to all compatible type lists.protected booleanadd(E o, Class<?> type, boolean batch)Adds an object to type lists beneath the given type hierarchy.booleanaddAll(Collection<? extends E> c)voidaddLater(LazyObjects<? extends E> c)Registers objects which will be created lazily as needed.protected booleanaddToList(E obj, List<E> list, boolean batch)voidclear()booleancontains(Object o)booleancontainsAll(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.booleanisEmpty()Iterator<E>iterator()booleanremove(Object o)protected booleanremove(Object o, boolean batch)Removes the object from all compatible type lists.protected booleanremove(Object o, Class<?> type, boolean batch)Removes an object from type lists beneath the given type hierarchy.booleanremoveAll(Collection<?> c)protected booleanremoveFromList(Object obj, List<E> list, boolean batch)booleanretainAll(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)intsize()Object[]toArray()<T> T[]toArray(T[] a)StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream
-
-
-
-
Method Detail
-
getAll
public List<E> getAll()
Gets a list of all registered objects.- Returns:
- Read-only list of all registered objects, or an empty list if none (this method never returns null).
-
get
public List<E> get(Class<?> type)
Gets a list of registered objects compatible with the given type.- Returns:
- New list of registered objects of the given type, or an empty list if no such objects exist (this method never returns null).
-
addLater
public void addLater(LazyObjects<? extends E> c)
Registers objects which will be created lazily as needed.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)orgetAll()).
-
size
public int size()
- Specified by:
sizein interfaceCollection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<E>
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<E>
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfaceCollection<E>
-
add
public boolean add(E o)
- Specified by:
addin interfaceCollection<E>
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<E>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<E>
-
addAll
public boolean addAll(Collection<? extends E> c)
- Specified by:
addAllin interfaceCollection<E>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAllin interfaceCollection<E>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<E>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<E>
-
add
protected boolean add(E o, boolean batch)
Adds the object to all compatible type lists.
-
remove
protected boolean remove(Object o, boolean batch)
Removes the object from all compatible type lists.
-
add
protected boolean add(E o, Class<?> type, boolean batch)
Adds an object to type lists beneath the given type hierarchy.
-
remove
protected boolean remove(Object o, Class<?> type, boolean batch)
Removes an object from type lists beneath the given type hierarchy.
-
getTypes
protected static Class<?>[] getTypes(Class<?> type)
Gets a new set containing the type and all its supertypes.
-
-