public class Dictionary extends Object
Values are always strings.
Constructor and Description |
---|
Dictionary()
Creates empty, with no parameters.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(String key)
Does a parameter exist with a particular key?
|
Dictionary |
duplicate()
Deep-copy of existing dictionary.
|
double |
getAsDouble(String key)
Retrieves a value from the dictionary, and converts to a
double . |
Optional<String> |
getAsString(String key)
Retrieves a value from the dictionary as a
String . |
Set<String> |
keys()
All keys existing in the dictionary.
|
void |
put(String key,
double value)
Inserts a key-value pair, after converting
value to a String . |
void |
put(String key,
String value)
Inserts a key-value pair.
|
void |
putCheck(Dictionary dictionary)
Inserts all key/value pairs from another dictionary, checking that no key already exists.
|
void |
putCheck(String key,
double value)
Inserts a key/value pair, checking that the key doesn't already exist.
|
void |
putCheck(String key,
String value)
Inserts a key/value pair, checking that the key doesn't already exist.
|
static Dictionary |
readFromFile(Path path)
Reads parameters from a Java
properties file.
|
void |
writeToFile(Path path)
Serializes the key-value parameters to a file.
|
public static Dictionary readFromFile(Path path) throws IOException
path
- the path where the properties file is located.IOException
- if the path doesn't exist, is in the correct format, or otherwise cannot
be read.public Dictionary duplicate()
public Optional<String> getAsString(String key)
String
.key
- the key to retrievekey
exists, otherwise Optional.empty()
.public double getAsDouble(String key)
double
.key
- the key to retrievekey
exists, otherwise Double.NaN
.public void put(String key, String value)
If the key already exists, its value is replaced.
key
- the key to insertvalue
- the value corresponding to key
public void put(String key, double value)
value
to a String
.key
- the key to insertvalue
- a floating-point value corresponding to key
public void putCheck(String key, String value) throws OperationFailedException
key
- the key to insertvalue
- a value corresponding to key
OperationFailedException
- if key
already exists in the dictionary.public void putCheck(String key, double value) throws OperationFailedException
key
- the key to insertvalue
- a floating-point value corresponding to key
OperationFailedException
- if key
already exists in the dictionary.public void putCheck(Dictionary dictionary) throws OperationFailedException
dictionary
- the dictionary to insert all key/value pairs fromOperationFailedException
- if key
already exists in the dictionary.public Set<String> keys()
The set is not backed by the dictionary. Changes to the set have no impact on the contents of the dictionary.
public boolean containsKey(String key)
key
- the keypublic void writeToFile(Path path) throws IOException
path
- path to write to.IOException
- if something goes wrong.Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.