Package org.anchoranalysis.core.value
Class Dictionary
Object
Dictionary
Collection of parameters represented by key-value pairs.
Values are always strings.
- Author:
- Owen Feehan
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(String key) Does a parameter exist with a particular key?Deep-copy of existing dictionary.double
getAsDouble
(String key) Retrieves a value from the dictionary, and converts to adouble
.getAsString
(String key) Retrieves a value from the dictionary as aString
.keys()
All keys existing in the dictionary.void
Inserts a key-value pair, after convertingvalue
to aString
.void
Inserts a key-value pair.void
Inserts a key/value pair, checking that the key doesn't already exist.void
Inserts a key/value pair, checking that the key doesn't already exist.void
putCheck
(Dictionary dictionary) Inserts all key/value pairs from another dictionary, checking that no key already exists.static Dictionary
readFromFile
(Path path) Reads parameters from a Java properties file.void
writeToFile
(Path path) Serializes the key-value parameters to a file.
-
Constructor Details
-
Dictionary
public Dictionary()Creates empty, with no parameters.
-
-
Method Details
-
readFromFile
Reads parameters from a Java properties file.- Parameters:
path
- the path where the properties file is located.- Returns:
- a newly created dictionary
- Throws:
IOException
- if the path doesn't exist, is in the correct format, or otherwise cannot be read.
-
duplicate
Deep-copy of existing dictionary.- Returns:
- a newly created dictionary, containing identical key-values.
-
getAsString
Retrieves a value from the dictionary as aString
.- Parameters:
key
- the key to retrieve- Returns:
- the value if
key
exists, otherwiseOptional.empty()
.
-
getAsDouble
Retrieves a value from the dictionary, and converts to adouble
.- Parameters:
key
- the key to retrieve- Returns:
- the value if
key
exists, otherwiseDouble.NaN
.
-
put
Inserts a key-value pair.If the key already exists, its value is replaced.
- Parameters:
key
- the key to insertvalue
- the value corresponding tokey
-
put
Inserts a key-value pair, after convertingvalue
to aString
.- Parameters:
key
- the key to insertvalue
- a floating-point value corresponding tokey
-
putCheck
Inserts a key/value pair, checking that the key doesn't already exist.- Parameters:
key
- the key to insertvalue
- a value corresponding tokey
- Throws:
OperationFailedException
- ifkey
already exists in the dictionary.
-
putCheck
Inserts a key/value pair, checking that the key doesn't already exist.- Parameters:
key
- the key to insertvalue
- a floating-point value corresponding tokey
- Throws:
OperationFailedException
- ifkey
already exists in the dictionary.
-
putCheck
Inserts all key/value pairs from another dictionary, checking that no key already exists.- Parameters:
dictionary
- the dictionary to insert all key/value pairs from- Throws:
OperationFailedException
- ifkey
already exists in the dictionary.
-
keys
All keys existing in the dictionary.The set is not backed by the dictionary. Changes to the set have no impact on the contents of the dictionary.
- Returns:
- a newly created set of all keys in the dictionary.
-
containsKey
Does a parameter exist with a particular key?- Parameters:
key
- the key- Returns:
- true iff the parameter exists.
-
writeToFile
Serializes the key-value parameters to a file.- Parameters:
path
- path to write to.- Throws:
IOException
- if something goes wrong.
-