Class AbstractMapStructure<K,​V extends SearchStructure<R> & MergeAndCopyStructure<V>,​R>

  • Type Parameters:
    K - The type of key in the underlying map - can be restricted in subclasses
    V - The type of values in the map. Values are nested structures which must:
    R - The type of the result values. The result type must be the same in every nested structure.
    Direct Known Subclasses:
    KeyStructure, RangeStructure, TwoColumnRangeStructure

    public abstract class AbstractMapStructure<K,​V extends SearchStructure<R> & MergeAndCopyStructure<V>,​R>
    extends SearchStructure<R>
    Abstract implementation for all structures that map keys to nested structures much like a map.

    This class provides a put(Object, SearchStructure) method to add nested structures. Adding multiple structures with the same key will result in those structures being merged. This makes setting up nested map structures easy.

    This abstract implementation makes no assumption about the underlying map implementation. The map instance is provided by subclasses via the constructor. Thus the SearchStructure.get(Object) method implementation must also be provided by subclasses using the chosen data structure.

    • Constructor Detail

      • AbstractMapStructure

        protected AbstractMapStructure​(java.util.Map<K,​V> map)
        Creates a new AbstractMapStructure with the specified map instance.
        Parameters:
        map - The map that should be used as underlying data structure.
    • Method Detail

      • put

        public void put​(K key,
                        V value)
        Puts a new element in the map. If there is already a value for the given key, the two values will be merged together. Thus existing values will never be overwritten.
        Parameters:
        key - key that maps to the specified value
        value - value to be associated with the specified key.
        See Also:
        Map.put(Object, Object), merge(AbstractMapStructure)
      • getMap

        protected java.util.Map<K,​V> getMap()
      • getValidResult

        protected SearchStructure<R> getValidResult​(V result)
        Checks whether the given result is null and returns a fall-back result (an empty ResultStructure) in that case.
        Parameters:
        result - a valid result or null.
        Returns:
        the given result or an EmptySearchStructure if the given result is null. Never returns null.
      • emptyResult

        protected SearchStructure<R> emptyResult()
        Simply returns an EmptySearchStructure. This is the typesafe representation of EMPTY.