Class StringPrefixMap<V extends Serializable>

java.lang.Object
nl.basjes.collections.prefixmap.StringPrefixMap<V>
Type Parameters:
V - The type of the value that is to be stored.
All Implemented Interfaces:
Serializable, Map<String,V>, PrefixMap<V>
Direct Known Subclasses:
ASCIIPrefixMap

public class StringPrefixMap<V extends Serializable> extends Object implements PrefixMap<V>, Serializable
The StringPrefixMap is an implementation of PrefixMap where the assumption is that the stored prefixes can be any character in a String.
See Also:
  • Constructor Details

    • StringPrefixMap

      public StringPrefixMap(boolean caseSensitive)
  • Method Details

    • configureKryo

      public static void configureKryo(Object kryoInstance)
      This is used to configure the provided Kryo instance if Kryo serialization is desired. The expected type here is Object because otherwise the Kryo library becomes a mandatory dependency on any project that uses Yauaa.
      Parameters:
      kryoInstance - The instance of com.esotericsoftware.kryo.Kryo that needs to be configured.
    • containsPrefix

      public boolean containsPrefix(PrimitiveIterator.OfInt prefix)
      Description copied from interface: PrefixMap

      Returns true if this map contains an exact mapping for the specified prefix.

      Note that implementations may be constructed to match either case sensitive or case insensitive.

      Specified by:
      containsPrefix in interface PrefixMap<V extends Serializable>
      Parameters:
      prefix - prefix whose presence in this prefixmap is to be checked
      Returns:
      true if this map contains an the exact mapping for the specified prefix.
    • put

      public V put(String prefix, V value)
      Description copied from interface: PrefixMap

      Stored the specified value as the result for the specified prefix.

      If for the specified prefix previously a value was present then the old value is replaced with the new value and the old value is returned.

      Note that implementations may be constructed to store this value for either case sensitive or case insensitive matching during retrieval.

      Specified by:
      put in interface Map<String,V extends Serializable>
      Specified by:
      put in interface PrefixMap<V extends Serializable>
      Parameters:
      prefix - prefix with which the specified value is to be associated
      value - value to be associated with the specified prefix
      Returns:
      the previous value of the specified prefix, or null if there was no mapping for prefix.
    • size

      public int size()
      Specified by:
      size in interface Map<String,V extends Serializable>
      Specified by:
      size in interface PrefixMap<V extends Serializable>
      Returns:
      the number of prefix-value mappings in this prefixmap
    • clear

      public void clear()
      Description copied from interface: PrefixMap
      The prefixmap will be empty after this call returns.
      Specified by:
      clear in interface Map<String,V extends Serializable>
      Specified by:
      clear in interface PrefixMap<V extends Serializable>
    • remove

      public V remove(String prefix)
      Description copied from interface: PrefixMap

      Removes the mapping for a prefix if present.

      Note that implementations may be constructed to remove either case sensitive (only this exact value) or case insensitive (all case variations).

      Specified by:
      remove in interface PrefixMap<V extends Serializable>
      Parameters:
      prefix - prefix whose mapping is to be removed from the prefixmap
      Returns:
      the previous value associated with prefix (may be null).
    • get

      public V get(String prefix)
      Description copied from interface: PrefixMap

      Return the value of the exact matching prefix.

      The value returned is the stored prefix for which is true: input.equals(prefix).

      Note that implementations may be constructed to match either case sensitive or case insensitive.

      Specified by:
      get in interface PrefixMap<V extends Serializable>
      Parameters:
      prefix - The string for which we need value of the stored prefix
      Returns:
      The value, null if not found.
    • getShortestMatch

      public V getShortestMatch(PrimitiveIterator.OfInt input)
      Description copied from interface: PrefixMap

      Return the value of the shortest matching prefix.

      The value returned is the shortest stored prefix for which is true: input.startsWith(prefix).

      Note that implementations may be constructed to match either case sensitive or case insensitive.

      Specified by:
      getShortestMatch in interface PrefixMap<V extends Serializable>
      Parameters:
      input - The string (iterator of Unicode CodePoints) for which we need value of the stored prefix.
      Returns:
      The value, null if not found.
    • getLongestMatch

      public V getLongestMatch(PrimitiveIterator.OfInt input)
      Description copied from interface: PrefixMap

      Return the value of the longest matching prefix.

      The value returned is the longest stored prefix for which is true: input.startsWith(prefix).

      Note that implementations may be constructed to match either case sensitive or case insensitive.

      Specified by:
      getLongestMatch in interface PrefixMap<V extends Serializable>
      Parameters:
      input - The string (iterator of Unicode CodePoints) for which we need value of the stored prefix.
      Returns:
      The value, null if not found.
    • getAllMatches

      public Iterator<V> getAllMatches(PrimitiveIterator.OfInt input)
      Description copied from interface: PrefixMap

      Returns List of all matches that have a value.

      The list contains all non-null values for the prefix values where this is true: input.startsWith(prefix).

      Note that implementations may be constructed to match either case sensitive or case insensitive.

      Specified by:
      getAllMatches in interface PrefixMap<V extends Serializable>
      Parameters:
      input - The string (iterator of Unicode CodePoints) for which we need value of the stored prefix.
      Returns:
      The list of values, an empty List if nothing is found.
    • entrySet

      public Set<Map.Entry<String,V>> entrySet()
      Specified by:
      entrySet in interface Map<String,V extends Serializable>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<String,V extends Serializable>
      Specified by:
      containsKey in interface PrefixMap<V extends Serializable>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<String,V extends Serializable>
      Specified by:
      containsValue in interface PrefixMap<V extends Serializable>
    • keySet

      public Set<String> keySet()
      Specified by:
      keySet in interface Map<String,V extends Serializable>
      Specified by:
      keySet in interface PrefixMap<V extends Serializable>
    • values

      public Collection<V> values()
      Specified by:
      values in interface Map<String,V extends Serializable>
      Specified by:
      values in interface PrefixMap<V extends Serializable>