|
|||||||||
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 of the Enum that represents the keys of the properties filepublic class PropertiesManager<T extends Enum<T>>
This class creates a management API for a Properties
file whose keys are
described by an Enum.
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). |
|
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. |
|
|
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). |
|
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. |
|
int |
getIntegerProperty(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. |
|
ManagedProperty<T> |
getManagedProperty(T property)
Get an object that will encapsulate the functionality of this manager specific to a single property. |
|
Properties |
getProperties()
Retrieve a Properties instance that contains the properties managed by this
instance.Please note that the returned Properties instance 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. |
|
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 Enum instances and property names (keys). |
|
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 |
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. |
|
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. |
|
|
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 all properties to permanent storage. Note that there is no guarantee that the modification and saving the properties will be atomic. |
|
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 Enum names and property keysevaluator
- 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 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 ManagedProperty<T> getManagedProperty(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() throws IllegalStateException
Properties
instance that contains the properties managed by this
instance.Properties
instance 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
IllegalStateException
- if the properties have not yet been loadedpublic Set<T> keySet() throws IllegalStateException
EnumSet.allOf(Class)
, but it is not
guaranteed.
IllegalStateException
- if the properties have not yet been loadedpublic 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
otherwisegetProperty(Enum)
public int getIntegerProperty(T property)
property
- the property to retrieve
NumberFormatException
- if both the current and default values are not integersgetProperty(Enum)
public long getLongProperty(T property)
property
- the property to retrieve
NumberFormatException
- if both the current and default values are not longsgetProperty(Enum)
public float getFloatProperty(T property)
property
- the property to retrieve
NumberFormatException
- if both the current and default values are not floatsgetProperty(Enum)
public double getDoubleProperty(T property)
property
- the property to retrieve
NumberFormatException
- if both the current and default values are not doublesgetProperty(Enum)
public <E extends Enum<E>> E getEnumProperty(T property, Class<E> type)
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 typegetProperty(Enum)
public String getRawProperty(T property) throws IllegalStateException
auto trim
is enabled, the value will also be trimmed of
whitespace.
property
- the property to retrieve
IllegalStateException
- if the properties have not yet been loadedpublic 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 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(Enum, 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(Enum)
)saveProperty(Enum, 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(Enum)
)saveProperty(Enum, Object)
public void setProperty(T property, String value) throws IllegalArgumentException, IllegalStateException
property
- the property whose value is being setvalue
- the value to set
IllegalArgumentException
- if a null
value is given (see
resetProperty(Enum)
)
IllegalStateException
- if the properties have not yet been loadedsaveProperty(Enum, String)
public <E extends Enum<E>> void saveProperty(T property, E value) throws IOException
saveProperty(Enum, String)
for additional details.getEnumProperty(Enum, 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 save the propertiespublic void saveProperty(T property, Object value) throws IOException
saveProperty(Enum, 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 save the propertiespublic void saveProperty(T property, String value) throws IOException
property
- the property whose value is being savedvalue
- the value to save
IOException
- if there is an error while attempting to save the propertiespublic 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) throws IllegalStateException
property
- the property whose value is being reset
IllegalStateException
- if the properties have not yet been loadedpublic void reset()
protected 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 |