- java.lang.Object
-
- com.aoapps.collections.PolymorphicMultimap<K,V>
-
public class PolymorphicMultimap<K,V> 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classPolymorphicMultimap.Lists<K,V>
-
Constructor Summary
Constructors Constructor Description PolymorphicMultimap(Class<K> upperBound)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends K>
List<Map.Entry<T,V>>getEntries(Class<T> clazz)Gets all entries registered of the given class.<T extends K>
List<Map.Entry<T,V>>getEntries(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)Gets all entries registered of the given class that match the given filter.<T extends K>
List<Map.Entry<T,V>>getEntriesFilterKey(Class<T> clazz, Predicate<? super T> filter)Gets all entries registered of the given class that match the given filter.<T extends K>
List<Map.Entry<T,V>>getEntriesFilterValue(Class<T> clazz, Predicate<? super V> filter)Gets all entries registered of the given class that match the given filter.<T extends K>
Map.Entry<T,V>getFirstEntry(Class<T> clazz)Gets the first entry registered of the given class.<T extends K>
Map.Entry<T,V>getFirstEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)Gets the first entry registered of the given class that match the given filter.<T extends K>
Map.Entry<T,V>getFirstEntryFilterKey(Class<T> clazz, Predicate<? super T> filter)Gets the first entry registered of the given class that match the given filter.<T extends K>
Map.Entry<T,V>getFirstEntryFilterValue(Class<T> clazz, Predicate<? super V> filter)Gets the first entry registered of the given class that match the given filter.<T extends K>
TgetFirstKey(Class<T> clazz)Gets the first key registered of the given class.<T extends K>
TgetFirstKey(Class<T> clazz, Predicate<? super T> filter)Gets the first key registered of the given class that match the given filter.<T extends K>
TgetFirstKeyFilterEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)Gets the first key registered of the given class that match the given filter.<T extends K>
TgetFirstKeyFilterValue(Class<T> clazz, Predicate<? super V> filter)Gets the first key registered of the given class that match the given filter.VgetFirstValue(Class<? extends K> clazz)Gets the first value registered of the given class.VgetFirstValue(Class<? extends K> clazz, Predicate<? super V> filter)Gets the first value registered of the given class that match the given filter.<T extends K>
VgetFirstValueFilterEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)Gets the first value registered of the given class that match the given filter.<T extends K>
VgetFirstValueFilterKey(Class<T> clazz, Predicate<? super T> filter)Gets the first value registered of the given class that match the given filter.<T extends K>
List<T>getKeys(Class<T> clazz)Gets all keys registered of the given class.<T extends K>
List<T>getKeys(Class<T> clazz, Predicate<? super T> filter)Gets all keys registered of the given class that match the given filter.<T extends K>
List<T>getKeysFilterEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)Gets all keys registered of the given class that match the given filter.<T extends K>
List<T>getKeysFilterValue(Class<T> clazz, Predicate<? super V> filter)Gets all keys registered of the given class that match the given filter.<T extends K>
Map.Entry<T,V>getLastEntry(Class<T> clazz)Gets the last entry registered of the given class.<T extends K>
Map.Entry<T,V>getLastEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)Gets the last entry registered of the given class that match the given filter.<T extends K>
Map.Entry<T,V>getLastEntryFilterKey(Class<T> clazz, Predicate<? super T> filter)Gets the last entry registered of the given class that match the given filter.<T extends K>
Map.Entry<T,V>getLastEntryFilterValue(Class<T> clazz, Predicate<? super V> filter)Gets the last entry registered of the given class that match the given filter.<T extends K>
TgetLastKey(Class<T> clazz)Gets the last key registered of the given class.<T extends K>
TgetLastKey(Class<T> clazz, Predicate<? super T> filter)Gets the last key registered of the given class that match the given filter.<T extends K>
TgetLastKeyFilterEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)Gets the last key registered of the given class that match the given filter.<T extends K>
TgetLastKeyFilterValue(Class<T> clazz, Predicate<? super V> filter)Gets the last key registered of the given class that match the given filter.VgetLastValue(Class<? extends K> clazz)Gets the last value registered of the given class.VgetLastValue(Class<? extends K> clazz, Predicate<? super V> filter)Gets the last value registered of the given class that match the given filter.<T extends K>
VgetLastValueFilterEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)Gets the last value registered of the given class that match the given filter.<T extends K>
VgetLastValueFilterKey(Class<T> clazz, Predicate<? super T> filter)Gets the last value registered of the given class that match the given filter.protected <T extends K>
PolymorphicMultimap.Lists<T,V>getLists(Class<T> clazz)Gets the lists registered for the given class.List<V>getValues(Class<? extends K> clazz)Gets all values registered of the given class.List<V>getValues(Class<? extends K> clazz, Predicate<? super V> filter)Gets all values registered of the given class that match the given filter.<T extends K>
List<V>getValuesFilterEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)Gets all values registered of the given class that match the given filter.<T extends K>
List<V>getValuesFilterKey(Class<T> clazz, Predicate<? super T> filter)Gets all values registered of the given class that match the given filter.voidput(K key, V value)Puts an key to the registry along with an associated value.
-
-
-
Method Detail
-
put
public void put(K key, V value)
Puts an key to the registry along with an associated value. The key is registered underall classes and interfacesit extends and implements, up to and including the upper boundK.This implementation favors lookup speed at O(1), and pays the price during
put(java.lang.Object, java.lang.Object).
-
getLists
protected <T extends K> PolymorphicMultimap.Lists<T,V> getLists(Class<T> clazz)
Gets the lists registered for the given class.- Returns:
- the lists or
nullwhen none registered
-
getKeys
public <T extends K> List<T> getKeys(Class<T> clazz)
Gets all keys 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
-
getKeys
public <T extends K> List<T> getKeys(Class<T> clazz, Predicate<? super T> filter)
Gets all keys 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
-
getKeysFilterValue
public <T extends K> List<T> getKeysFilterValue(Class<T> clazz, Predicate<? super V> filter)
Gets all keys 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
-
getKeysFilterEntry
public <T extends K> List<T> getKeysFilterEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)
Gets all keys 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
-
getValues
public List<V> getValues(Class<? extends K> clazz)
Gets all values 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
-
getValues
public List<V> getValues(Class<? extends K> clazz, Predicate<? super V> filter)
Gets all values 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
-
getValuesFilterKey
public <T extends K> List<V> getValuesFilterKey(Class<T> clazz, Predicate<? super T> filter)
Gets all values 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
-
getValuesFilterEntry
public <T extends K> List<V> getValuesFilterEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)
Gets all values 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
-
getEntries
public <T extends K> List<Map.Entry<T,V>> getEntries(Class<T> clazz)
Gets all entries 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
-
getEntries
public <T extends K> List<Map.Entry<T,V>> getEntries(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)
Gets all entries 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
-
getEntriesFilterKey
public <T extends K> List<Map.Entry<T,V>> getEntriesFilterKey(Class<T> clazz, Predicate<? super T> filter)
Gets all entries 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
-
getEntriesFilterValue
public <T extends K> List<Map.Entry<T,V>> getEntriesFilterValue(Class<T> clazz, Predicate<? super V> filter)
Gets all entries 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
-
getFirstKey
public <T extends K> T getFirstKey(Class<T> clazz)
Gets the first key registered of the given class.- Returns:
- the first key registered or
nullfor none registered
-
getFirstKey
public <T extends K> T getFirstKey(Class<T> clazz, Predicate<? super T> filter)
Gets the first key registered of the given class that match the given filter.- Returns:
- the first key registered that matches the filter or
nullfor none registered
-
getFirstKeyFilterValue
public <T extends K> T getFirstKeyFilterValue(Class<T> clazz, Predicate<? super V> filter)
Gets the first key registered of the given class that match the given filter.- Returns:
- the first key registered that matches the filter or
nullfor none registered
-
getFirstKeyFilterEntry
public <T extends K> T getFirstKeyFilterEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)
Gets the first key registered of the given class that match the given filter.- Returns:
- the first key registered that matches the filter or
nullfor none registered
-
getFirstValue
public V getFirstValue(Class<? extends K> clazz)
Gets the first value registered of the given class.- Returns:
- the first value registered or
nullfor none registered
-
getFirstValue
public V getFirstValue(Class<? extends K> clazz, Predicate<? super V> filter)
Gets the first value registered of the given class that match the given filter.- Returns:
- the first value registered that matches the filter or
nullfor none registered
-
getFirstValueFilterKey
public <T extends K> V getFirstValueFilterKey(Class<T> clazz, Predicate<? super T> filter)
Gets the first value registered of the given class that match the given filter.- Returns:
- the first value registered that matches the filter or
nullfor none registered
-
getFirstValueFilterEntry
public <T extends K> V getFirstValueFilterEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)
Gets the first value registered of the given class that match the given filter.- Returns:
- the first value registered that matches the filter or
nullfor none registered
-
getFirstEntry
public <T extends K> Map.Entry<T,V> getFirstEntry(Class<T> clazz)
Gets the first entry registered of the given class.- Returns:
- the first entry registered or
nullfor none registered
-
getFirstEntry
public <T extends K> Map.Entry<T,V> getFirstEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)
Gets the first entry registered of the given class that match the given filter.- Returns:
- the first entry registered that matches the filter or
nullfor none registered
-
getFirstEntryFilterKey
public <T extends K> Map.Entry<T,V> getFirstEntryFilterKey(Class<T> clazz, Predicate<? super T> filter)
Gets the first entry registered of the given class that match the given filter.- Returns:
- the first entry registered that matches the filter or
nullfor none registered
-
getFirstEntryFilterValue
public <T extends K> Map.Entry<T,V> getFirstEntryFilterValue(Class<T> clazz, Predicate<? super V> filter)
Gets the first entry registered of the given class that match the given filter.- Returns:
- the first entry registered that matches the filter or
nullfor none registered
-
getLastKey
public <T extends K> T getLastKey(Class<T> clazz)
Gets the last key registered of the given class.- Returns:
- the last key registered or
nullfor none registered
-
getLastKey
public <T extends K> T getLastKey(Class<T> clazz, Predicate<? super T> filter)
Gets the last key registered of the given class that match the given filter.- Returns:
- the last key registered that matches the filter or
nullfor none registered
-
getLastKeyFilterValue
public <T extends K> T getLastKeyFilterValue(Class<T> clazz, Predicate<? super V> filter)
Gets the last key registered of the given class that match the given filter.- Returns:
- the last key registered that matches the filter or
nullfor none registered
-
getLastKeyFilterEntry
public <T extends K> T getLastKeyFilterEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)
Gets the last key registered of the given class that match the given filter.- Returns:
- the last key registered that matches the filter or
nullfor none registered
-
getLastValue
public V getLastValue(Class<? extends K> clazz)
Gets the last value registered of the given class.- Returns:
- the last value registered or
nullfor none registered
-
getLastValue
public V getLastValue(Class<? extends K> clazz, Predicate<? super V> filter)
Gets the last value registered of the given class that match the given filter.- Returns:
- the last value registered that matches the filter or
nullfor none registered
-
getLastValueFilterKey
public <T extends K> V getLastValueFilterKey(Class<T> clazz, Predicate<? super T> filter)
Gets the last value registered of the given class that match the given filter.- Returns:
- the last value registered that matches the filter or
nullfor none registered
-
getLastValueFilterEntry
public <T extends K> V getLastValueFilterEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)
Gets the last value registered of the given class that match the given filter.- Returns:
- the last value registered that matches the filter or
nullfor none registered
-
getLastEntry
public <T extends K> Map.Entry<T,V> getLastEntry(Class<T> clazz)
Gets the last entry registered of the given class.- Returns:
- the last entry registered or
nullfor none registered
-
getLastEntry
public <T extends K> Map.Entry<T,V> getLastEntry(Class<T> clazz, Predicate<? super Map.Entry<T,V>> filter)
Gets the last entry registered of the given class that match the given filter.- Returns:
- the last entry registered that matches the filter or
nullfor none registered
-
getLastEntryFilterKey
public <T extends K> Map.Entry<T,V> getLastEntryFilterKey(Class<T> clazz, Predicate<? super T> filter)
Gets the last entry registered of the given class that match the given filter.- Returns:
- the last entry registered that matches the filter or
nullfor none registered
-
-