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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description StringPrefixMap(boolean caseSensitive)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()The prefixmap will be empty after this call returns.static voidconfigureKryo(Object kryoInstance)This is used to configure the provided Kryo instance if Kryo serialization is desired.booleancontainsKey(Object key)booleancontainsPrefix(String prefix)Returnstrueif this map contains an exact mapping for the specified prefix.booleancontainsValue(Object value)Set<Map.Entry<String,V>>entrySet()Vget(String prefix)Return the value of theexactmatching prefix.VgetLongestMatch(String input)Return the value of the longest matching prefix.VgetShortestMatch(String input)Return the value of theshortestmatching prefix.Set<String>keySet()Vput(String prefix, V value)Stored the specified value as the result for the specified prefix.Vremove(String prefix)Removes the mapping for a prefix if present.intsize()Collection<V>values()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
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(String prefix)
Description copied from interface:PrefixMapReturns
trueif 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:
containsPrefixin interfacePrefixMap<V extends Serializable>- Parameters:
prefix- prefix whose presence in this prefixmap is to be checked- Returns:
trueif this map contains an the exact mapping for the specified prefix.
-
put
public V put(String prefix, V value)
Description copied from interface:PrefixMapStored 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:
putin interfaceMap<String,V extends Serializable>- Specified by:
putin interfacePrefixMap<V extends Serializable>- Parameters:
prefix- prefix with which the specified value is to be associatedvalue- value to be associated with the specified prefix- Returns:
- the previous value of the specified
prefix, ornullif there was no mapping forprefix.
-
size
public int size()
- Specified by:
sizein interfaceMap<String,V extends Serializable>- Specified by:
sizein interfacePrefixMap<V extends Serializable>- Returns:
- the number of prefix-value mappings in this prefixmap
-
clear
public void clear()
Description copied from interface:PrefixMapThe prefixmap will be empty after this call returns.- Specified by:
clearin interfaceMap<String,V extends Serializable>- Specified by:
clearin interfacePrefixMap<V extends Serializable>
-
remove
public V remove(String prefix)
Description copied from interface:PrefixMapRemoves 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:
removein interfacePrefixMap<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:PrefixMapReturn the value of the
exactmatching 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:
getin interfacePrefixMap<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(String input)
Description copied from interface:PrefixMapReturn the value of the
shortestmatching 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:
getShortestMatchin interfacePrefixMap<V extends Serializable>- Parameters:
input- The string for which we need value of the stored prefix- Returns:
- The value, null if not found.
-
getLongestMatch
public V getLongestMatch(String input)
Description copied from interface:PrefixMapReturn 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:
getLongestMatchin interfacePrefixMap<V extends Serializable>- Parameters:
input- The string for which we need value of the stored prefix- Returns:
- The value, null if not found.
-
entrySet
public Set<Map.Entry<String,V>> entrySet()
- Specified by:
entrySetin interfaceMap<String,V extends Serializable>
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<String,V extends Serializable>- Specified by:
containsKeyin interfacePrefixMap<V extends Serializable>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<String,V extends Serializable>- Specified by:
containsValuein interfacePrefixMap<V extends Serializable>
-
keySet
public Set<String> keySet()
- Specified by:
keySetin interfaceMap<String,V extends Serializable>- Specified by:
keySetin interfacePrefixMap<V extends Serializable>
-
values
public Collection<V> values()
- Specified by:
valuesin interfaceMap<String,V extends Serializable>- Specified by:
valuesin interfacePrefixMap<V extends Serializable>
-
-