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 TypeClassDescriptionclassRepresents 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) booleanRetruns the specified property as abooleanbooleangetPropertyAsBoolean(String key, boolean defaultValue) Retruns the specified property as abooleanchargetPropertyAsChar(String key) Returns the specified property as acharchargetPropertyAsChar(String key, char defaultValue) Returns the specified property as achardoubleReturns the specified property as adoubledoublegetPropertyAsDouble(String key, double defaultValue) Returns the specified property as adoubleintgetPropertyAsInt(String key) Returns the specified property as anintintgetPropertyAsInt(String key, int defaultValue) Returns the specified property as anintlonggetPropertyAsLong(String key) Returns the specified property as alonglonggetPropertyAsLong(String key, long defaultValue) Returns the specified property as alongstatic CaselessPropertiesinstance()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_NORMALstartTransaction(int priority) Starts a transaction for updating multiple values simultaneouslyvoidstore()Saves the current property set, then reloads the current statevoidstore(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:
getPropertyin classProperties
-
getProperty
- Overrides:
getPropertyin classProperties
-
getPropertyAsChar
Returns the specified property as achar- Parameters:
key- the hashtable key- Returns:
- the first
charof 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
charof the value returned bygetProperty(String);defaultValueif 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;defaultValueif 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;defaultValueif 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;defaultValueif the property does not exist or is not parsable as adouble
-
getPropertyAsBoolean
Retruns the specified property as abooleanAccepted truthy values:
1trueyes
- Parameters:
key- the hashtable key- Returns:
- the value returned by
getProperty(String)cast as aboolean;falseif the property does not exist or does not match an accepted truthy value
-
getPropertyAsBoolean
Retruns the specified property as abooleanAccepted truthy values:
1trueyes
- Parameters:
key- the hashtable key- Returns:
- the value returned by
getProperty(String)cast as aboolean;defaultValueif the property does not exist;falseif 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
keyalready exists; elsenull
-
keySet
-
entrySet
-
keys
- Overrides:
keysin 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
prioritywins. Transactions with the samepriorityare 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 andPropertiesReloadedEventis fired
-