Class 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.
    • Constructor Detail

      • PolymorphicMultimap

        public PolymorphicMultimap​(Class<K> upperBound)
    • 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 under all classes and interfaces it extends and implements, up to and including the upper bound K.

        This implementation favors lookup speed at O(1), and pays the price during put(java.lang.Object, java.lang.Object).

      • getLists

        protected <T extends KPolymorphicMultimap.Lists<T,​V> getLists​(Class<T> clazz)
        Gets the lists registered for the given class.
        Returns:
        the lists or null when none registered
      • getKeys

        public <T extends KList<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 KList<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 KList<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 KList<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 KList<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 KList<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 KList<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 KList<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 KList<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 KList<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 null for 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 null for 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 null for 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 null for 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 null for 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 null for none registered
      • getFirstValueFilterKey

        public <T extends KV 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 null for none registered
      • getFirstValueFilterEntry

        public <T extends KV 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 null for none registered
      • getFirstEntry

        public <T extends KMap.Entry<T,​V> getFirstEntry​(Class<T> clazz)
        Gets the first entry registered of the given class.
        Returns:
        the first entry registered or null for none registered
      • getFirstEntry

        public <T extends KMap.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 null for none registered
      • getFirstEntryFilterKey

        public <T extends KMap.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 null for none registered
      • getFirstEntryFilterValue

        public <T extends KMap.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 null for 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 null for 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 null for 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 null for 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 null for 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 null for 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 null for none registered
      • getLastValueFilterKey

        public <T extends KV 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 null for none registered
      • getLastValueFilterEntry

        public <T extends KV 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 null for none registered
      • getLastEntry

        public <T extends KMap.Entry<T,​V> getLastEntry​(Class<T> clazz)
        Gets the last entry registered of the given class.
        Returns:
        the last entry registered or null for none registered
      • getLastEntry

        public <T extends KMap.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 null for none registered
      • getLastEntryFilterKey

        public <T extends KMap.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 null for none registered
      • getLastEntryFilterValue

        public <T extends KMap.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.
        Returns:
        the last entry registered that matches the filter or null for none registered