public class PersistentProperties extends Object implements Serializable, Cloneable
The type of the stored data is not obvious and should be known the the caller code. That's why there are different method to store/retrieve data (each method for each type).
important note : once you have stored some data with a key you cannot re-use this key for another type. Or if you want to do that then put the property to null before. Important note : for the time being (this may change later) instances of this class are not garbage collected| Modifier and Type | Class and Description |
|---|---|
static class |
PersistentProperties.FileStore |
static interface |
PersistentProperties.Store
this class defines the way the properties are made persistent and read.
|
| Constructor and Description |
|---|
PersistentProperties(String name)
uses a fileStore.
|
PersistentProperties(String name,
PersistentProperties.Store store)
creates a PersistenProperties with a specific store.
|
| Modifier and Type | Method and Description |
|---|---|
<T> T |
getArray(String key,
Class<T> arrayClass)
returns a value stored in the properties as an array.
|
Boolean |
getBoolean(String key)
gets a Boolean value stored with this key
|
Double |
getDouble(String key)
get a double value associated with the key
|
Float |
getFloat(String key)
gets a Float from a value in the properties
|
Integer |
getInteger(String key)
get a Integer value from the Properties
|
List |
getList(String key)
returns a list stored in the properties.
|
Map |
getMap(String key)
returns a Map stored in the properties.
|
Object |
getObject(String key)
tries to return an object out of a String.
|
String |
getString(String key)
gets a String associated with a key
|
<T> T |
getStruct(String key,
Class<T> structClass)
returns an object stored with the struct convention from the properties.
|
<T,V extends T> |
putArray(String key,
Class<T> arrayClass,
V value)
registers an array in the properties.
|
Boolean |
putBoolean(String key,
boolean bool)
put a Boolean value in the properties
|
Double |
putDouble(String key,
double val)
puts a Double value in the properties
|
Float |
putFloat(String key,
float val)
registers a Float as a Property
|
Integer |
putInteger(String key,
int value)
put an Integer value in the Properties
|
List |
putList(String key,
List list)
registers a List to the properties.
|
Map |
putMap(String key,
Map map)
stores a Map as a String in the properties.
|
Object |
putObject(String key,
Object obj)
Puts an object with no type specification in the properties.
|
String |
putString(String key,
String value)
registers a String in the properties
|
<T> T |
putStruct(String key,
Class<T> structClass,
T value)
This will store objects that stick to a convention (and known as struct.
|
public PersistentProperties(String name, PersistentProperties.Store store)
name - (beware should be consistent with that are legal for your store!)store - public PersistentProperties(String name)
name - (beware should be consistent with a fileName)public Integer putInteger(String key, int value)
key - value - public Integer getInteger(String key)
key - public Boolean putBoolean(String key, boolean bool)
key - bool - public Boolean getBoolean(String key)
key - public Double putDouble(String key, double val)
key - val - public Double getDouble(String key)
key - public Float putFloat(String key, float val)
key - val - public Float getFloat(String key)
key - public String putString(String key, String value)
key - value - public String getString(String key)
key - public <T,V extends T> T putArray(String key, Class<T> arrayClass, V value)
Double[] arrDbl = {2.44, 6.66} ;
Number[] arrNumber = myProperties.putArray("valueArray", Number[].class, arrDbl) ;
Doing this:
Number[] arrNumber = myProperties.putArray("valueArray", Double[].class, arrDbl) ;
will work but you may end up with an ArrayStoreException
when dealing later with arrNumberT - type of Array with elements of type XV - array of any type Y that is assignment compatible to Xkey - arrayClass - such as String[].classvalue - could be an array which is "assignable to"
this array elements should be of a primitive type, wrapper types, String, BigDecimal or Arrays of arrays of these types.
Arrays of other types of Objects are not supported (some "structs" -see below-would work)public <T> T getArray(String key, Class<T> arrayClass)
T - key - arrayClass - public <T> T putStruct(String key, Class<T> structClass, T value)
T - key - structClass - the name of the class that will be used to analyse previous valuevalue - any object that sticks to this struct conventionpublic <T> T getStruct(String key, Class<T> structClass)
T - key - structClass - public List putList(String key, List list)
key - list - public List getList(String key)
key - public Map putMap(String key, Map map)
key - map - public Map getMap(String key)
key - public Object putObject(String key, Object obj)
key - obj - Copyright © 2013 LSST. All Rights Reserved.