Package tv.phantombot
Class CaselessProperties
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<Object,
Object>
- Direct Known Subclasses:
CaselessCommandLineArguments
Provides an implementation of
Properties
where the key
is case-insensitive and thread-safe
Provides methods which allow casting values as a char, int, long, double, or boolean
Provides the ability to perform a thread-safe update of multiple values as a transaction
- Author:
- gmt2001
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Represents a transaction which apples new values to the property set simultaneously -
Field Summary
FieldsFields inherited from class java.util.Properties
defaults
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionentrySet()
getProperty
(String key) getProperty
(String key, String defaultValue) boolean
Retruns the specified property as aboolean
boolean
getPropertyAsBoolean
(String key, boolean defaultValue) Retruns the specified property as aboolean
char
getPropertyAsChar
(String key) Returns the specified property as achar
char
getPropertyAsChar
(String key, char defaultValue) Returns the specified property as achar
double
Returns the specified property as adouble
double
getPropertyAsDouble
(String key, double defaultValue) Returns the specified property as adouble
int
getPropertyAsInt
(String key) Returns the specified property as anint
int
getPropertyAsInt
(String key, int defaultValue) Returns the specified property as anint
long
getPropertyAsLong
(String key) Returns the specified property as along
long
getPropertyAsLong
(String key, long defaultValue) Returns the specified property as along
static CaselessProperties
instance()
keys()
keySet()
putIfAbsent
(String key, Object value) Searches for the property with the specified key in this property list.Starts a transaction for updating multiple values simultaneously atCaselessProperties.Transaction.PRIORITY_NORMAL
startTransaction
(int priority) Starts a transaction for updating multiple values simultaneouslyvoid
store()
Saves the current property set, then reloads the current statevoid
store
(boolean reload) Saves the current property setMethods inherited from class java.util.Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, equals, forEach, get, getOrDefault, hashCode, isEmpty, list, list, load, load, loadFromXML, merge, propertyNames, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
Field Details
-
serialVersionUID
public static final long serialVersionUID- See Also:
-
-
Constructor Details
-
CaselessProperties
public CaselessProperties()
-
-
Method Details
-
instance
-
put
-
getProperty
- Overrides:
getProperty
in classProperties
-
getProperty
- Overrides:
getProperty
in classProperties
-
getPropertyAsChar
Returns the specified property as achar
- Parameters:
key
- the hashtable key- Returns:
- the first
char
of the value returned bygetProperty(String)
- Throws:
IndexOutOfBoundsException
- if the property does not exist or is empty
-
getPropertyAsChar
Returns the specified property as achar
- Parameters:
key
- the hashtable keydefaultValue
- a default value- Returns:
- the first
char
of the value returned bygetProperty(String)
;defaultValue
if the property does not exist or is empty
-
getPropertyAsInt
Returns the specified property as anint
- Parameters:
key
- the hashtable key- Returns:
- the value returned by
getProperty(String)
cast as anint
- Throws:
NumberFormatException
- if the property does not exist or is empty
-
getPropertyAsInt
Returns the specified property as anint
- Parameters:
key
- the hashtable keydefaultValue
- a default value- Returns:
- the value returned by
getProperty(String)
cast as anint
;defaultValue
if the property does not exist or is not parsable as anint
-
getPropertyAsLong
Returns the specified property as along
- Parameters:
key
- the hashtable key- Returns:
- the value returned by
getProperty(String)
cast as along
- Throws:
NumberFormatException
- if the property does not exist or is empty
-
getPropertyAsLong
Returns the specified property as along
- Parameters:
key
- the hashtable keydefaultValue
- a default value- Returns:
- the value returned by
getProperty(String)
cast as along
;defaultValue
if the property does not exist or is not parsable as along
-
getPropertyAsDouble
Returns the specified property as adouble
- Parameters:
key
- the hashtable key- Returns:
- the value returned by
getProperty(String)
cast as adouble
- Throws:
NumberFormatException
- if the property does not exist or is empty
-
getPropertyAsDouble
Returns the specified property as adouble
- Parameters:
key
- the hashtable keydefaultValue
- a default value- Returns:
- the value returned by
getProperty(String)
cast as adouble
;defaultValue
if the property does not exist or is not parsable as adouble
-
getPropertyAsBoolean
Retruns the specified property as aboolean
Accepted truthy values:
1
true
yes
- Parameters:
key
- the hashtable key- Returns:
- the value returned by
getProperty(String)
cast as aboolean
;false
if the property does not exist or does not match an accepted truthy value
-
getPropertyAsBoolean
Retruns the specified property as aboolean
Accepted truthy values:
1
true
yes
- Parameters:
key
- the hashtable key- Returns:
- the value returned by
getProperty(String)
cast as aboolean
;defaultValue
if the property does not exist;false
if the value does not match an accepted truthy value
-
putIfAbsent
Searches for the property with the specified key in this property list. If the property is found, returns the current value; otherwise, adds the property to the property list- Parameters:
key
- the property keyvalue
- the value to put if the property key does not exist- Returns:
- the current value if
key
already exists; elsenull
-
keySet
-
entrySet
-
keys
- Overrides:
keys
in classProperties
-
startTransaction
Starts a transaction for updating multiple values simultaneously atCaselessProperties.Transaction.PRIORITY_NORMAL
- Returns:
- a new
CaselessProperties.Transaction
-
startTransaction
Starts a transaction for updating multiple values simultaneouslyIf multiple transactions editing the same values are comitted within 15 seconds of each other, the transaction with the highest
priority
wins. Transactions with the samepriority
are first-come first-served- Parameters:
priority
- the priority level, between 0 and 100- Returns:
- a new
CaselessProperties.Transaction
-
store
public void store()Saves the current property set, then reloads the current state -
store
public void store(boolean reload) Saves the current property set- Parameters:
reload
- iftrue
, the state is also reloaded andPropertiesReloadedEvent
is fired
-