- java.lang.Object
-
- com.aoapps.collections.PolymorphicRegistry<U>
-
public class PolymorphicRegistry<U> extends Object
A registry of objects by their class, along with all their parent classes and interfaces, up to and including an upper bound. The registry is highly concurrent, and performs registry lookups in O(1).- Author:
- AO Industries, Inc.
-
-
Constructor Summary
Constructors Constructor Description PolymorphicRegistry(Class<U> upperBound)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(U instance)Adds a instance to the registry.<T extends U>
List<T>get(Class<T> clazz)Gets all instances registered of the given class.<T extends U>
List<T>get(Class<T> clazz, Predicate<? super T> filter)Gets all instances registered of the given class that match the given filter.<T extends U>
TgetFirst(Class<T> clazz)Gets the first instance registered of the given class.<T extends U>
TgetFirst(Class<T> clazz, Predicate<? super T> filter)Gets the first instance registered of the given class that match the given filter.<T extends U>
TgetLast(Class<T> clazz)Gets the last instance registered of the given class.<T extends U>
TgetLast(Class<T> clazz, Predicate<? super T> filter)Gets the last instance registered of the given class that match the given filter.
-
-
-
Method Detail
-
add
public void add(U instance)
Adds a instance to the registry. The instance is registered underall classes and interfacesit extends and implements, up to and including the upper boundU.This implementation favors lookup speed at O(1), and pays the price during
add(java.lang.Object).
-
get
public <T extends U> List<T> get(Class<T> clazz)
Gets all instances registered of the given class. They are returned in the order registered. When an object is registered more than once, it will appear in the list multiple times. The list is a snapshot and will not change over time.- Returns:
- the unmodifiable list of all objects registered of the given class, or an empty list when none registered
-
get
public <T extends U> List<T> get(Class<T> clazz, Predicate<? super T> filter)
Gets all instances registered of the given class that match the given filter. They are returned in the order registered. When an object is registered more than once, it will appear in the list multiple times. The list is a snapshot and will not change over time.- Returns:
- the unmodifiable list of all objects registered of the given class that match the filter, or an empty list when none registered
-
getFirst
public <T extends U> T getFirst(Class<T> clazz)
Gets the first instance registered of the given class.- Returns:
- the first instance registered or
nullfor none registered
-
getFirst
public <T extends U> T getFirst(Class<T> clazz, Predicate<? super T> filter)
Gets the first instance registered of the given class that match the given filter.- Returns:
- the first instance registered that matches the filter or
nullfor none registered
-
getLast
public <T extends U> T getLast(Class<T> clazz)
Gets the last instance registered of the given class.- Returns:
- the last instance registered or
nullfor none registered
-
-