Class KeyCollectionImpl.KeyMap<E,​K>

  • All Implemented Interfaces:
    java.io.Serializable
    Enclosing class:
    KeyCollectionImpl<E>

    static class KeyCollectionImpl.KeyMap<E,​K>
    extends java.lang.Object
    implements java.io.Serializable
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) boolean allowDuplicates
      True to allow duplicate values if they are not null
      (package private) boolean allowDuplicatesNull
      True to allow duplicate null values
      (package private) boolean allowNull
      True to allow null keys
      (package private) java.util.Comparator<K> comparator
      Comparator to use for sorting (if null, elements are not sorted)
      (package private) boolean count
      True to count only number of occurrences of equal elements (can only be set on keyMap[0] storing the elements)
      (package private) IList<K> keysList
      Key storage if this is a KeyListImpl sorted by this key map, otherwise null.
      (package private) java.util.Map<K,​java.lang.Object> keysMap
      Key storage if not sorted.
      (package private) java.util.function.Function<E,​K> mapper
      A mapper to extract keys out of element.
    • Constructor Summary

      Constructors 
      Constructor Description
      KeyMap()  
    • Field Detail

      • mapper

        java.util.function.Function<E,​K> mapper
        A mapper to extract keys out of element. For the element itself, this is always an IdentMapper.
      • allowNull

        boolean allowNull
        True to allow null keys
      • allowDuplicates

        boolean allowDuplicates
        True to allow duplicate values if they are not null
      • allowDuplicatesNull

        boolean allowDuplicatesNull
        True to allow duplicate null values
      • comparator

        java.util.Comparator<K> comparator
        Comparator to use for sorting (if null, elements are not sorted)
      • keysMap

        java.util.Map<K,​java.lang.Object> keysMap
        Key storage if not sorted. The values are single elements or a list of elements. Note that we cannot use TreeMap as K may not be comparable. One of keysMap or keysList is used.
      • keysList

        IList<K> keysList
        Key storage if this is a KeyListImpl sorted by this key map, otherwise null. One of keysMap or keysList is used.
      • count

        boolean count
        True to count only number of occurrences of equal elements (can only be set on keyMap[0] storing the elements)
    • Constructor Detail

      • KeyMap

        KeyMap()
    • Method Detail

      • isPrimaryMap

        boolean isPrimaryMap()
      • getKey

        K getKey​(E elem)
      • containsKey

        boolean containsKey​(java.lang.Object key)
      • containsValue

        boolean containsValue​(java.lang.Object key,
                              java.lang.Object value)
      • containsValue

        boolean containsValue​(java.lang.Object value)
      • getContainedKey

        Option<E> getContainedKey​(java.lang.Object key)
      • getContainedValue

        Option<E> getContainedValue​(java.lang.Object value)
      • addThrow

        void addThrow​(K key,
                      E elem)
      • add

        java.lang.Object add​(K key,
                             E elem)
        Add element to key map.
        Parameters:
        key - key of element
        elem - element
        Returns:
        SYMBOL_ADDED if element has successfully been added, SYMBOL_ERROR_NULL_KEY if a null key is not allowed, otherwise the key which is rejected because of a duplicate exception
      • remove

        Option<E> remove​(java.lang.Object key,
                         boolean matchValue,
                         java.lang.Object value,
                         KeyCollectionImpl keyColl)
        Remove element from key map.
        Parameters:
        key - key of object to remove
        matchValue - true if value must match to remove entry
        value - value of object to remove
        keyColl - key collection which stores object
        Returns:
        removed object
      • doRemoveAllByKey

        private void doRemoveAllByKey​(K key,
                                      KeyCollectionImpl<E> keyColl,
                                      java.util.Collection<E> coll)
        Removes element by key. If there are duplicates, all elements are removed.
        Parameters:
        keyMap - key map
        key - key of element to remove
        coll - collection to store all removed elements, null to not store them
      • getDistinctKeys

        java.util.Set<K> getDistinctKeys()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object