Package org.apache.pivot.collections
Interface Dictionary<K,V>
-
- Type Parameters:
K- Type for the keys in this dictionary.V- Type for each of the values in the dictionary.
- All Known Subinterfaces:
Map<K,V>
- All Known Implementing Classes:
Action.NamedActionDictionary,ApplicationContext.ResourceCacheDictionary,BeanAdapter,CategorySeries,Component.StyleDictionary,Component.UserDataDictionary,Element.ElementDictionary,Element.NamespaceDictionary,EnumMap,HashMap,ImmutableMap,MapAdapter,MIMEType,QueryDictionary,Resources,SynchronizedMap,TableView.SortDictionary
public interface Dictionary<K,V>Interface representing a set of key/value pairs.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classDictionary.Pair<K,V>Class representing a key/value pair.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default booleancontainsAny(K... keys)Determines if any of the given keys exists in the dictionary.booleancontainsKey(K key)Tests the existence of a key in the dictionary.default java.lang.Objectcopy(K key, Dictionary<K,V> source)Copy the value from one dictionary to this one.Vget(K key)Retrieves the value for the given key.default booleangetBoolean(K key)Using the other methods in this interface, retrieve a boolean value from this dictionary; returning false if the key does not exist.default booleangetBoolean(K key, boolean defaultValue)Using the other methods in this interface, retrieve a boolean value from this dictionary; returning a default value if the key does not exist.default java.awt.ColorgetColor(K key)Using the other methods in this interface, retrieve aColorvalue from this dictionary; returningnullif the key does not exist.default VgetFirst(K... keys)Retrieves the value of the first of the given keys that exists in the dictionary (that is, the first key for whichcontainsKey(K)returns true).default java.awt.FontgetFont(K key)Using the other methods in this interface, retrieve aFontvalue from this dictionary; returningnullif the key does not exist.default intgetInt(K key)Using the other methods in this interface, retrieve an integer value from this dictionary; returning 0 if the key does not exist.default intgetInt(K key, int defaultValue)Using the other methods in this interface, retrieve an integer value from this dictionary; returning the given default if the key does not exist.default java.lang.StringgetString(K key)Retrieve a String value from this dictionary; returning null if the key does not exist.default java.lang.StringgetString(K key, java.lang.String defaultValue)Retrieve a String value from this dictionary; returning null if the key does not exist.Vput(K key, V value)Sets the value of the given key, creating a new entry or replacing the existing value.default voidputAll(Map<K,V> map)Put all the key/value pairs from the given map into this dictionary.Vremove(K key)Removes a key/value pair from the map.
-
-
-
Method Detail
-
get
V get(K key)
Retrieves the value for the given key.- Parameters:
key- The key whose value is to be returned.- Returns:
- The value corresponding to
key, or null if the key does not exist. Will also return null if the key refers to a null value. UsecontainsKey(K)to distinguish between these two cases.
-
put
V put(K key, V value)
Sets the value of the given key, creating a new entry or replacing the existing value.- Parameters:
key- The key whose value is to be set.value- The value to be associated with the given key.- Returns:
- The value previously associated with the key.
-
remove
V remove(K key)
Removes a key/value pair from the map.- Parameters:
key- The key whose mapping is to be removed.- Returns:
- The value that was removed.
-
containsKey
boolean containsKey(K key)
Tests the existence of a key in the dictionary.- Parameters:
key- The key whose presence in the dictionary is to be tested.- Returns:
trueif the key exists in the dictionary;false, otherwise.
-
containsAny
default boolean containsAny(K... keys)
Determines if any of the given keys exists in the dictionary.- Parameters:
keys- The list of keys to search for in the dictionary.- Returns:
trueifcontainsKey(K)returns true for any of the given keys, orfalseif none of the keys exist.
-
getFirst
default V getFirst(K... keys)
Retrieves the value of the first of the given keys that exists in the dictionary (that is, the first key for whichcontainsKey(K)returns true).- Parameters:
keys- The list of keys to search for in the dictionary.- Returns:
- The first value found, or
nullif either the value is null for the first key found, or none of the keys exists in the dictionary. UsecontainsAny(K...)to determine the difference.
-
getString
default java.lang.String getString(K key)
Retrieve a String value from this dictionary; returning null if the key does not exist.- Parameters:
key- The key for the (supposed)Stringvalue.- Returns:
- The string value, or
nullif the key is not present.
-
getString
default java.lang.String getString(K key, java.lang.String defaultValue)
Retrieve a String value from this dictionary; returning null if the key does not exist.- Parameters:
key- The key for the (supposed)Stringvalue.defaultValue- The string to return if the key is not present.- Returns:
- The string value, or the default value if the key is not present.
-
getInt
default int getInt(K key)
Using the other methods in this interface, retrieve an integer value from this dictionary; returning 0 if the key does not exist.- Parameters:
key- The key for the (supposed)Integervalue to retrieve (actually anyNumberwill work).- Returns:
- The integer value, or 0 if the key is not present.
-
getInt
default int getInt(K key, int defaultValue)
Using the other methods in this interface, retrieve an integer value from this dictionary; returning the given default if the key does not exist.- Parameters:
key- The key for the (supposed)Integervalue to retrieve (actually anyNumberwill work).defaultValue- The value to return if the key is not present.- Returns:
- The integer value, or the default value if the key is not present.
-
getBoolean
default boolean getBoolean(K key)
Using the other methods in this interface, retrieve a boolean value from this dictionary; returning false if the key does not exist.- Parameters:
key- The key for the (supposed)Booleanvalue to retrieve.- Returns:
- The boolean value, or false if the key is not present.
-
getBoolean
default boolean getBoolean(K key, boolean defaultValue)
Using the other methods in this interface, retrieve a boolean value from this dictionary; returning a default value if the key does not exist.- Parameters:
key- The key for the (supposed)Booleanvalue to retrieve.defaultValue- What to return if the key is not present.- Returns:
- The boolean value, or the default if the key is not present.
-
getColor
default java.awt.Color getColor(K key)
Using the other methods in this interface, retrieve aColorvalue from this dictionary; returningnullif the key does not exist.- Parameters:
key- The key for the (supposed)Colorvalue to retrieve.- Returns:
- The color value, or
nullif the key is not present.
-
getFont
default java.awt.Font getFont(K key)
Using the other methods in this interface, retrieve aFontvalue from this dictionary; returningnullif the key does not exist.- Parameters:
key- The key for the (supposed)Fontvalue to retrieve.- Returns:
- The font value, or
nullif the key is not present.
-
putAll
default void putAll(Map<K,V> map)
Put all the key/value pairs from the given map into this dictionary.- Parameters:
map- The other map to use.
-
copy
default java.lang.Object copy(K key, Dictionary<K,V> source)
Copy the value from one dictionary to this one.- Parameters:
key- Key for value to be copied.source- The source to copy from.- Returns:
- The previous value in the target dictionary.
-
-