public class LookupTable extends Object
The LookupTable class is responsible for storing and returning values which are organized by keys. Values can be added with the put method. To query a String value for a given key, the getStringValue method can be used. To query and automatically convert values to types other than String, please have a look at the get method family.
This class is not guaranteed to be threadsafe.
| Constructor and Description |
|---|
LookupTable()
Creates and initializes a LookupTable instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(String key,
String value)
Adds a new element with a specified key and value to the LookupTable.
|
void |
clear()
Removes all key/value pairs of the collection
|
boolean |
contains(String key)
Tests if the collection contains a value for a given key.
|
boolean |
getBooleanValue(String key,
boolean defaultValue)
Returns a value of an element converted to a boolean for a given key.
|
byte[] |
getBytesValue(String key,
int size,
byte[] defaultValue)
Returns a byte array value of an element for a given key.
|
Color |
getColorValue(String key,
Color defaultValue)
Returns a Color value of an element for a given key.
|
int |
getCount()
Returns the number of key/value pairs of this collection.
|
int |
getIntegerValue(String key,
int defaultValue)
Returns a value of an element converted to an integer for a given key.
|
Level |
getLevelValue(String key,
Level defaultValue)
Returns a value of an element converted to a Level value for a given key.
|
FileRotate |
getRotateValue(String key,
FileRotate defaultValue)
Returns a value of an element converted to a FileRotate value for a given key.
|
long |
getSizeValue(String key,
long defaultValue)
Returns a value of an element converted to an integer for a
given key.
|
String |
getStringValue(String key,
String defaultValue)
Returns a value of an element for a given key.
|
long |
getTimespanValue(String key,
long defaultValue)
Returns a value of an element converted to an integer for a given key.
|
void |
put(String key,
String value)
Adds or updates an element with a specified key and value to
the LookupTable.
|
void |
remove(String key)
Removes an existing element with a given key from this lookup table.
|
static long |
sizeToLong(String value,
long defaultResult) |
public void put(String key, String value)
This method adds a new element with a given key and value to the collection of key/value pairs. If an element for the given key already exists, the original element's value is updated.
key - The key of the elementvalue - The value of the elementNullPointerException - if the key or value argument is nullpublic void add(String key, String value)
This method adds a new element with a given key and value to the collection of key/value pairs. If an element for the given key already exists, the original element's value is not updated.
key - The key of the elementvalue - The value of the elementNullPointerException - if the key or value argument is nullpublic void remove(String key)
key - The key of the element to removeNullPointerException - if the key argument is nullpublic boolean contains(String key)
key - The key to test forNullPointerException - if the key argument is nullpublic void clear()
public int getCount()
public String getStringValue(String key, String defaultValue)
key - The key whose value to returndefaultValue - The value to return if the given key is unknownNullPointerException - If the key argument is nullpublic boolean getBooleanValue(String key, boolean defaultValue)
This method returns a boolean value of true if the found value of the given key matches either "true", "1" or "yes" and false otherwise. If the supplied key is unknown, the defaultValue argument is returned.
key - The key whose value to return. Cannot be nulldefaultValue - The value to return if the given key is unknownNullPointerException - if the key argument is nullpublic int getIntegerValue(String key, int defaultValue)
key - The key whose value to returndefaultValue - The value to return if the given key is unknownNullPointerException - if the key argument is nullpublic Level getLevelValue(String key, Level defaultValue)
key - The key whose value to returndefaultValue - The value to return if the given key is unknownNullPointerException - If the key argument is nullpublic long getSizeValue(String key, long defaultValue)
This method returns the defaultValue argument if either the supplied key is unknown or the found value is not a valid integer or ends with an unknown byte unit. Only non-negative integer values are recognized as valid.
It is possible to specify a size unit at the end of the value. If a known unit is found, this function multiplies the resulting value with the corresponding factor. For example, if the value of the element is "1KB", the return value of this function would be 1024.
The following table lists the available units together with a short description and the corresponding factor:
| Unit Name | Description | Factor |
|---|---|---|
| KB | Kilo Byte | 1024 |
| MB | Mega Byte | 1024^2 |
| GB | Giga Byte | 1024^3 |
If no unit is specified, this function defaults to the KB unit.
key - The key whose value to returndefaultValue - The value to return if the given key is unknownNullPointerException - if the key argument is nullpublic static long sizeToLong(String value, long defaultResult)
public long getTimespanValue(String key, long defaultValue)
This method returns the defaultValue argument if either the supplied key is unknown or the found value is not a valid integer or ends with an unknown time span unit.
It is possible to specify a time span unit at the end of the value. If a known unit is found, this function multiplies the resulting value with the corresponding factor. For example, if the value of the element is "1s", the return value of this function would be 1000.
The following table lists the available units together with a short description and the corresponding factor.
Unit Name Description Factor - - - s Seconds 1000 m Minutes 60*s h Hours 60*m d Days 24*h
If no unit is specified, this function defaults to the Seconds unit. Please note that the value is always returned in milliseconds.
key - The key whose value to returndefaultValue - The value to return if the given key is unknownNullPointerException - if the key argument is nullpublic FileRotate getRotateValue(String key, FileRotate defaultValue)
key - The key whose value to returndefaultValue - The value to return if the given key is unknownNullPointerException - If the key argument is nullpublic Color getColorValue(String key, Color defaultValue)
| Bytes | Format |
|---|---|
| 3 | RRGGBB |
| 4 | AARRGGBB |
| Other | Ignored |
key - The key whose value to returndefaultValue - The value to return if the given key is unknown or if the found value has an invalid formatNullPointerException - If the key argument is nullpublic byte[] getBytesValue(String key, int size, byte[] defaultValue)
key - The key whose value to return. This parameter should not be null.
Throws NullPointerException if the key argument is null.size - The desired size in bytes of the returned byte array. If
the element value does not have the expected size, it is
shortened or padded automatically.defaultValue - The value to return if the given key is unknown or if the
found value has an invalid format.Copyright © 2023. All rights reserved.