public class PropertiesImpl extends AbstractPropertiesBase implements Properties
A better Properties class. This implementation class is thread-safe.
Properties.Factory, Properties.Mode| Modifier and Type | Field and Description |
|---|---|
protected Pattern |
dotIdentifierPattern |
protected Pattern |
dotIntegerPattern |
protected Pattern |
dotKeyValuePattern |
protected static String |
REF_TOKEN |
private static long |
serialVersionUID |
contentType, lock, map| Constructor and Description |
|---|
PropertiesImpl() |
PropertiesImpl(InputStream in) |
PropertiesImpl(InputStream in,
Charset charset) |
PropertiesImpl(Map map) |
PropertiesImpl(Properties legacy)
TODO - implement compatibility mode
Some slight information loss here is unavoidable.
|
PropertiesImpl(Reader in) |
PropertiesImpl(URL url) |
| Modifier and Type | Method and Description |
|---|---|
Object |
beanValue(Class<?> clazz,
String keyBase) |
BigDecimal |
bigDecimalValue(String key) |
BigInteger |
bigValue(String key) |
BitSet |
bitsetValue(String key) |
boolean |
booleanValue(String key) |
Properties |
convertToLegacyProperties()
Get java.util.Properties from ours
|
Date |
dateValue(String key)
Date value here is assumed to be a long
|
Date |
dateValue(String key,
String format)
I should really deprecate this - you should really use long values as dates in a serialization.
|
boolean |
equals(Object obj) |
String |
get(String key)
Get the value of the property; concatenate multiple lines.
|
List<String> |
getComments(String key)
Get the list of comments, return an empty list if none
|
Map<String,String> |
getFlattenedMap()
Just return Strings
|
Properties |
getGroup(GroupParams params) |
List<String> |
getKeyGroup(String keyBase) |
String |
getKeyRef(String key) |
List<String> |
getList(String keyBase)
This method relies on the convention of using numbers at
the end of a property key to represent a list member.
|
List<String> |
getListKeys(String keyBase)
Return keys which match the pattern keyBase.0, keyBase.1, keyBase.2, etc.
|
List<String> |
getMapKeys(String keyBase)
Specialty method used with a map that has been serialized in the form keyBase dot integer dot k|v
For example,
0.0.k=a key
0.0.v=a value
|
List<String> |
getMatchingKeys(String partial)
Return the keys which match the partial key submitted
|
Map<String,ValueModel> |
getPropertyMap()
Can be used to get direct access to the Entry data structures
|
char |
getSeparator(String key)
The char found in the parse, normally '='
|
Node |
getTree()
Use "\\." as the separator
|
Node |
getTree(GroupParams params)
Get the properties as a tree of nodes with a selector
a.b.c=something
a.b.c.d=something else
a.b.c.e.f=item
a.b.c.e=item2
|
int |
hashCode() |
boolean |
hasKeyLike(String partial)
Like containsKey but matching on the partial
|
boolean |
hasValue(String key)
Returns true if the key exists and has a non-empty value
|
protected void |
initMap() |
int |
intValue(String key)
Coerce to an integer value.
|
List<String> |
listValue(String key) |
List<String> |
listValue(String key,
String delimiter) |
long |
longValue(String key)
Coerce to a long value.
|
Properties |
merge(Properties props)
This is a merge function, existing keys which do not collide
with the incoming are kept, keys that collide are overwritten with the new values
TODO, cause comments to come over as well
|
Properties |
merge(Properties props,
boolean mergeComments)
Overwrite existing keys with the new ones, keep those existing ones that don't collide
This operation is non-destructive on the input
|
void |
mergeIntoSystemProperties()
Not easily reversable, use with care
|
void |
put(String key,
BigDecimal bd) |
void |
put(String key,
BigInteger bi) |
void |
put(String key,
boolean val) |
void |
put(String key,
char val) |
void |
put(String key,
char separator,
Comment comment,
String... values) |
void |
put(String key,
char separator,
String... values) |
void |
put(String key,
Comment comment,
String... values) |
void |
put(String key,
double val) |
void |
put(String key,
float val) |
void |
put(String key,
int val) |
void |
put(String key,
List<String> values) |
void |
put(String key,
String... values)
Yes, multi-valued (multi-lined) properties are in the spec.
|
void |
putKeyRef(String newRefKey,
String existingKey) |
void |
putList(List<String> list,
char sep,
Comment comment,
String rootKey) |
void |
putList(List<String> list,
Comment comment,
String rootKey) |
void |
putList(List<String> list,
String rootKey)
create property keys and values based on a root key and a list in the form:
rootKey.0= list.get(0);
rootKey.1= list.get(1);
and so on.
|
void |
putList(String key,
char ch,
List<String> list) |
void |
synchronize(Node rootNode)
Cause a graph to become the contents of the properties file.
|
clear, containsKey, containsValue, getContentType, isEmpty, keySet, remove, setContentType, size, toString, valuesclone, finalize, getClass, notify, notifyAll, wait, wait, waitclear, containsKey, getContentType, setContentType, sizeprivate static final long serialVersionUID
protected Pattern dotIntegerPattern
protected Pattern dotIdentifierPattern
protected Pattern dotKeyValuePattern
protected static final String REF_TOKEN
public PropertiesImpl()
public PropertiesImpl(Properties legacy)
TODO - implement compatibility mode Some slight information loss here is unavoidable. For example if a colon is used as the separator in the original, that information will be lost. If you need a more exact translation you can do that with the lexer and parser classes by reading in the data directly from the properties file instead of reading in with java.util.Properties and then converting.
public PropertiesImpl(Map map)
public PropertiesImpl(URL url)
public PropertiesImpl(InputStream in)
public PropertiesImpl(InputStream in, Charset charset)
public PropertiesImpl(Reader in)
protected void initMap()
public String get(String key)
get in interface Propertieskey - RuntimeException - if key is not present.public void put(String key, String... values)
put in interface Propertieskey - values - public void put(String key, List<String> values)
put in interface Propertiespublic void put(String key, Comment comment, String... values)
put in interface Propertiespublic void put(String key, char separator, Comment comment, String... values)
put in interface Propertiespublic void put(String key, int val)
put in interface Propertiespublic void put(String key, BigInteger bi)
put in interface Propertiespublic void put(String key, BigDecimal bd)
put in interface Propertiespublic void put(String key, float val)
put in interface Propertiespublic void put(String key, double val)
put in interface Propertiespublic void put(String key, boolean val)
put in interface Propertiespublic void put(String key, char val)
put in interface Propertiespublic Map<String,ValueModel> getPropertyMap()
PropertiesgetPropertyMap in interface Propertiespublic Map<String,String> getFlattenedMap()
PropertiesgetFlattenedMap in interface Propertiespublic List<String> getComments(String key)
PropertiesgetComments in interface Propertiespublic char getSeparator(String key)
PropertiesgetSeparator in interface Propertiespublic int hashCode()
hashCode in class AbstractPropertiesBasepublic boolean equals(Object obj)
equals in class AbstractPropertiesBasepublic Properties merge(Properties props)
merge in interface Propertiesprops - public Properties merge(Properties props, boolean mergeComments)
Propertiesmerge in interface Propertiespublic Node getTree()
getTree in interface Propertiespublic Node getTree(GroupParams params)
PropertiesGet the properties as a tree of nodes with a selector a.b.c=something a.b.c.d=something else a.b.c.e.f=item a.b.c.e=item2
getTree in interface Propertiespublic Properties getGroup(GroupParams params)
public List<String> getMatchingKeys(String partial)
partial - public boolean hasKeyLike(String partial)
PropertieshasKeyLike in interface Propertiespublic int intValue(String key)
PropertiesintValue in interface Propertiespublic boolean booleanValue(String key)
booleanValue in interface Propertiespublic long longValue(String key)
PropertieslongValue in interface Propertiespublic Date dateValue(String key)
PropertiesdateValue in interface Propertiespublic Date dateValue(String key, String format) throws ParseException
dateValue in interface PropertiesParseExceptionpublic boolean hasValue(String key)
PropertieshasValue in interface Propertiespublic void synchronize(Node rootNode)
Propertiessynchronize in interface Propertiespublic void mergeIntoSystemProperties()
mergeIntoSystemProperties in interface Propertiespublic List<String> getMapKeys(String keyBase)
PropertiesgetMapKeys in interface Propertiespublic List<String> getListKeys(String keyBase)
PropertiesgetListKeys in interface Propertiespublic List<String> getList(String keyBase)
Properties
This method relies on the convention of using numbers at
the end of a property key to represent a list member. The total
list is the set of all similar keys with key as the base
and dot delimited integers at the end. Suppose the following
(from the Tanukisoft wrapper.conf):
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../lib/myapp.jar
wrapper.java.classpath.3=../lib/mysql.jar
wrapper.java.classpath.4=../classes
Then calling getList("wrapper.java.classpath") would
return all the values above, in numeric order, as a List.
If key does not exist but numbered properties exist, the
key is synthesized. if no numbered properties exist, an
empty list is returned. If the key does not exist and no numbered
keys exist, the method returns an empty list
Numbers need not be sequential
getList in interface Propertiespublic List<String> listValue(String key)
listValue in interface Propertiespublic List<String> listValue(String key, String delimiter)
listValue in interface Propertiespublic BitSet bitsetValue(String key)
bitsetValue in interface Propertiespublic BigInteger bigValue(String key)
bigValue in interface Propertiespublic BigDecimal bigDecimalValue(String key)
bigDecimalValue in interface Propertiespublic Object beanValue(Class<?> clazz, String keyBase)
beanValue in interface Propertiespublic void putList(List<String> list, String rootKey)
Propertiescreate property keys and values based on a root key and a list in the form: rootKey.0= list.get(0); rootKey.1= list.get(1); and so on. This method is a complement to using getList(rootKey).
putList in interface Propertiespublic void putList(List<String> list, Comment comment, String rootKey)
putList in interface Propertiespublic Properties convertToLegacyProperties()
PropertiesconvertToLegacyProperties in interface PropertiesCopyright © 2011-2014 David R. Smith. All Rights Reserved.