|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.syphr.prom.PropertiesManager<T>
T
- the type that represents the keys of the properties filepublic class PropertiesManager<T>
This class creates a management API for a Properties
file.
Constructor Summary | |
---|---|
PropertiesManager(File file,
Properties defaults,
Translator<T> translator,
Evaluator evaluator,
ExecutorService executor)
Construct a new manager for the given properties file. |
Method Summary | ||
---|---|---|
void |
addPropertyListener(PropertyListener<T> listener)
Add a listener for property events (such as change, save, load). |
|
PropertiesManager<T> |
copy(File newFile)
Copy the current state of this manager to a new instance that is based on a different file. |
|
protected Retriever |
createRetriever()
Build a new Retriever instance that will be used by the
evaluator to request the values of nested property
references. |
|
boolean |
getBooleanProperty(T property)
Retrieve the value of the given property as a boolean. |
|
double |
getDoubleProperty(T property)
Retrieve the value of the given property as a double. |
|
double |
getDoublePropertyFallback(T property)
Retrieve the value of the given property as a double. |
|
|
getEnumProperty(T property,
Class<E> type)
Retrieve the value of the given property as an Enum constant of the given type. Note that this method requires the Enum constants to all have upper case names (following Java naming conventions). |
|
|
getEnumPropertyFallback(T property,
Class<E> type)
Retrieve the value of the given property as an Enum constant of the given type. |
|
protected Evaluator |
getEvaluator()
Retrieve the object that converts nested property references into evaluated strings. |
|
File |
getFile()
|
|
float |
getFloatProperty(T property)
Retrieve the value of the given property as a float. |
|
float |
getFloatPropertyFallback(T property)
Retrieve the value of the given property as a float. |
|
int |
getIntegerProperty(T property)
Retrieve the value of the given property as an integer. |
|
int |
getIntegerPropertyFallback(T property)
Retrieve the value of the given property as an integer. |
|
long |
getLongProperty(T property)
Retrieve the value of the given property as a long. |
|
long |
getLongPropertyFallback(T property)
Retrieve the value of the given property as a long. |
|
Properties |
getProperties()
Retrieve a Properties object that contains the properties managed
by this instance.Please note that the returned Properties object is not connected
in any way to this manager and is only a snapshot of what the properties
looked like at the time the request was fulfilled. |
|
String |
getProperty(T property)
Get the current value of the given property. |
|
PropertyManager<T> |
getPropertyManager(T property)
Get an object that will encapsulate the functionality of this manager specific to a single property. |
|
String |
getRawProperty(T property)
Get the current value of the given property, but without translating references. |
|
protected Retriever |
getRetriever()
Get the Retriever instance used internally to fetch values using an
Evaluator . |
|
Translator<T> |
getTranslator()
Retrieve the object that translates between key objects and property names. |
|
boolean |
isAutoTrim()
Determine whether or not values will be automatically trimmed of whitespace as they are read. |
|
boolean |
isDefault(T property)
Determine whether or not the given property is set to its default value. |
|
boolean |
isModified()
Determine whether or not any property has been modified since the last load or save. |
|
boolean |
isModified(T property)
Determine whether or not the given property has been modified since it was last load or saved. |
|
boolean |
isReferencing(T property1,
T property2)
Determine whether or not one property holds references to another property. |
|
boolean |
isSavingDefaults()
Determine whether or not default values will be written to the properties file when and if it is saved. |
|
Set<T> |
keySet()
Retrieve the set of keys currently in use by this manager. |
|
void |
load()
Load the current values of all properties. This method will block and wait for the properties to be loaded. |
|
Future<Void> |
loadNB()
Load the properties file. |
|
void |
loadProperty(T property)
Load the current value of the given property from the file without modifying the values of any other properties. |
|
Future<Void> |
loadPropertyNB(T property)
Load the current value of the given property from the file without modifying the values of any other properties. |
|
Reference |
referenceAt(T property,
int position)
Retrieve the reference to another property from within the value of the given property at the given position. |
|
void |
removePropertyListener(PropertyListener<T> listener)
Remove a property listener. |
|
void |
reset()
Reset the properties to the original defaults. |
|
void |
resetProperty(T property)
Reset the given property to its default value. |
|
void |
save()
Save the current values of all properties. This method will block and wait for the properties to be saved. |
|
Future<Void> |
saveNB()
Save the current values of all properties. This method will not block to wait for the properties to be saved. |
|
void |
saveProperty(T property)
Save the current value of the given property to the file without modifying the values of any other properties in the file. |
|
|
saveProperty(T property,
E value)
Save the given property using an Enum constant. |
|
void |
saveProperty(T property,
Object value)
Save the given property using an object's string representation. |
|
void |
saveProperty(T property,
String value)
Modify the value of the given property and save only that change to permanent storage. |
|
Future<Void> |
savePropertyNB(T property)
Save the current value of the given property to the file without modifying the values of any other properties in the file. |
|
void |
setAutoTrim(boolean autoTrim)
Set the flag that determines whether or not values will be automatically trimmed of whitespace as they are read. |
|
void |
setComment(String comment)
Set a comment that will be written to the file that stores the properties managed by this instance. The default is no comment. |
|
|
setProperty(T property,
E value)
Set the given property using an Enum constant. |
|
void |
setProperty(T property,
Object value)
Set the given property using an object's string representation. |
|
void |
setProperty(T property,
String value)
Set the given property using a string. |
|
void |
setSavingDefaults(boolean savingDefaults)
Set the flag that determines whether or not default values are saved to the properties file when and if it is written. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PropertiesManager(File file, Properties defaults, Translator<T> translator, Evaluator evaluator, ExecutorService executor)
file
- the file system location of the properties represented heredefaults
- default values for the properties represented heretranslator
- the translator to convert between key objects and property namesevaluator
- the evaluator to convert nested property references into fully
evaluated stringsexecutor
- a service to handle potentially long running tasks, such as
interacting with the file systemMethod Detail |
---|
public PropertiesManager<T> copy(File newFile)
save()
. This would
effectively copy the properties file.PropertyManager
instances. It will also install the current Translator
,
Evaluator
, ExecutorService
, as well as the default
Properties
into the new instance.
newFile
- the file to which the new instance will be based
public void setSavingDefaults(boolean savingDefaults)
savingDefaults
- the flag to setpublic boolean isSavingDefaults()
true
if default values will be written out; false
otherwisepublic void setAutoTrim(boolean autoTrim)
autoTrim
- the flag to setpublic boolean isAutoTrim()
true
if values will be trimmed; false
otherwisepublic void setComment(String comment)
comment
- the comment to setpublic File getFile()
public PropertyManager<T> getPropertyManager(T property)
property
- the property to manage
public void addPropertyListener(PropertyListener<T> listener)
listener
- the listener to addpublic void removePropertyListener(PropertyListener<T> listener)
listener
- the listener to removepublic Translator<T> getTranslator()
protected Evaluator getEvaluator()
public Properties getProperties()
Properties
object that contains the properties managed
by this instance.Properties
object is not connected
in any way to this manager and is only a snapshot of what the properties
looked like at the time the request was fulfilled.
Properties
instance containing the properties managed
by this instance (including defaults)public Set<T> keySet()
public String getProperty(T property)
property
- the property to retrieve
null
if an error occurred
while attempting to read the properties)public boolean getBooleanProperty(T property)
property
- the property to retrieve
true
if the value of the property is "true" (case
insensitive); false
otherwisepublic int getIntegerProperty(T property) throws NumberFormatException
property
- the property to retrieve
NumberFormatException
- if the current value is not an integerpublic int getIntegerPropertyFallback(T property) throws NumberFormatException
property
- the property to retrieve
NumberFormatException
- if both the current and default values are not integerspublic long getLongProperty(T property) throws NumberFormatException
property
- the property to retrieve
NumberFormatException
- if the current value is not a longpublic long getLongPropertyFallback(T property) throws NumberFormatException
property
- the property to retrieve
NumberFormatException
- if both the current and default values are not longspublic float getFloatProperty(T property) throws NumberFormatException
property
- the property to retrieve
NumberFormatException
- if the current value is not a floatpublic float getFloatPropertyFallback(T property) throws NumberFormatException
property
- the property to retrieve
NumberFormatException
- if both the current and default values are not floatspublic double getDoubleProperty(T property) throws NumberFormatException
property
- the property to retrieve
NumberFormatException
- if the current value is not a doublepublic double getDoublePropertyFallback(T property) throws NumberFormatException
property
- the property to retrieve
NumberFormatException
- if both the current and default values are not doublespublic <E extends Enum<E>> E getEnumProperty(T property, Class<E> type) throws IllegalArgumentException
E
- the type of Enum that will be returnedproperty
- the property to retrievetype
- the Enum type to which the property will be converted
IllegalArgumentException
- if the current value is not a valid constant of the given
typepublic <E extends Enum<E>> E getEnumPropertyFallback(T property, Class<E> type) throws IllegalArgumentException
E
- the type of Enum that will be returnedproperty
- the property to retrievetype
- the Enum type to which the property will be converted
IllegalArgumentException
- if both the current and default values are not valid
constants of the given typepublic String getRawProperty(T property)
auto trim
is enabled, the value will also be trimmed of
whitespace.
property
- the property to retrieve
public boolean isDefault(T property)
property
- the property to check
true
if the given property has its default value;
false
otherwisepublic boolean isReferencing(T property1, T property2)
property1
- the property to check for referencesproperty2
- the target referenced property
true
if the first property references the second;
false
otherwisepublic Reference referenceAt(T property, int position)
null
.
property
- the property to search for the requested referenceposition
- the position to check for a reference
null
otherwisepublic void loadProperty(T property) throws IOException
isModified(Object)
will return false
for the given
property after this call completes, but it will return true
for any other properties that have been modified since the last load or
save.loadPropertyNB(Object)
for a non-blocking version.
property
- the property to load
IOException
- if there is an error while attempting to read the property
from the filepublic Future<Void> loadPropertyNB(T property)
isModified(Object)
will return false
for the given
property after this call completes, but it will return true
for any other properties that have been modified since the last load or
save.loadProperty(Object)
for a blocking version.
property
- the property to save
IOException
- if there is an error while attempting to write the property
to the filepublic void load() throws IOException
loadNB()
for a non-blocking version.
IOException
- if there is an error while attempting to load the propertiespublic Future<Void> loadNB()
load()
for a blocking version.
Future
representing this load requestpublic <E extends Enum<E>> void setProperty(T property, E value) throws IllegalArgumentException
getEnumProperty(Object, Class)
for additional details.
E
- the type of Enum value to setproperty
- the property whose value is being setvalue
- the value to set
IllegalArgumentException
- if a null
value is given (see
resetProperty(Object)
)saveProperty(Object, Enum)
public void setProperty(T property, Object value) throws IllegalArgumentException
property
- the property whose value is being setvalue
- the value to set
IllegalArgumentException
- if a null
value is given (see
resetProperty(Object)
)saveProperty(Object, Object)
public void setProperty(T property, String value) throws IllegalArgumentException
property
- the property whose value is being setvalue
- the value to set
IllegalArgumentException
- if a null
value is given (see
resetProperty(Object)
)saveProperty(Object, String)
public <E extends Enum<E>> void saveProperty(T property, E value) throws IOException
saveProperty(Object, String)
for additional details.getEnumProperty(Object, Class)
for additional details.
E
- the type of Enum value to saveproperty
- the property whose value is being savedvalue
- the value to save
IOException
- if there is an error while attempting to write the property
to the filepublic void saveProperty(T property, Object value) throws IOException
saveProperty(Object, String)
for additional details.
property
- the property whose value is being savedvalue
- the value to save
IOException
- if there is an error while attempting to write the property
to the filepublic void saveProperty(T property, String value) throws IOException
save()
or
saveNB()
is called.
property
- the property whose value is being savedvalue
- the value to save
IOException
- if there is an error while attempting to write the property
to the filepublic void saveProperty(T property) throws IOException
isModified(Object)
will return false
for the given
property after this call completes, but it will return true
for any other properties that have been modified since the last load or
save.savePropertyNB(Object)
for a non-blocking version.
property
- the property to save
IOException
- if there is an error while attempting to write the property
to the filepublic Future<Void> savePropertyNB(T property)
isModified(Object)
will return false
for the given
property after this call completes, but it will return true
for any other properties that have been modified since the last load or
save.saveProperty(Object)
for a blocking version.
property
- the property to save
IOException
- if there is an error while attempting to write the property
to the filepublic void save() throws IOException
saveNB()
for a non-blocking version.
IOException
- if there is an error while attempting to save the propertiespublic Future<Void> saveNB()
save()
for a blocking version.
public void resetProperty(T property)
property
- the property whose value is being resetpublic void reset()
public boolean isModified(T property)
property
- the property to check
true
if this property has been modified since the
last time it was loaded or saved; false
otherwisepublic boolean isModified()
true
if any property known to this instance has been
modified since the last load or save; false
otherwiseprotected Retriever createRetriever()
Retriever
instance that will be used by the
evaluator
to request the values of nested property
references.
Retriever
protected Retriever getRetriever()
Retriever
instance used internally to fetch values using an
Evaluator
.
createRetriever()
,
Evaluator
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |