|
ProgramixGenericLib v5.0.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.programix.value.ValueMap
public class ValueMap
Maps String keys to Value values with an iteration order
matching the insertion order.
Many of the methods on this class declare that they might throw a
ValueException or a ValueMapException or a subclass of
ValueMapException, ValueMapRequiredKeyException. All
three of these exceptions are subclasses of RuntimeException so
they do not have to be explicitly caught (aka "can-catch" exceptions
or "unchecked" exceptions).
ValueMap's can be populated
directly from files (and other stream sources) when those files are
in a format very similar to that which Properties reads,
specifically:
| Constructor Summary | |
|---|---|
ValueMap()
Creates a mapping that locks on this instance of ValueMap. |
|
ValueMap(Object lock)
Creates a mapping which synchronizes on the specified lock object. |
|
| Method Summary | ||
|---|---|---|
boolean |
containsAnyKeyWithPrefix(String prefix)
Returns true if there are currently any keys that start with the specified prefix. |
|
boolean |
containsKey(String key)
Returns true if a Value is currently stored for the
specified key. |
|
static ValueMap |
createFrom(BufferedReader in)
Creates a mapping from the specified data source. |
|
static ValueMap |
createFrom(File source)
|
|
static ValueMap |
createFrom(InputStream rawIn)
|
|
static ValueMap |
createFrom(Map<?,?> map)
Copies the entries from the specified Map into a new
ValueMap. |
|
static ValueMap |
createFrom(Reader rawIn)
Creates a mapping from the specified data source. |
|
static ValueMap |
createFrom(URL source)
|
|
static ValueMap |
createFromFile(String sourceFilename)
|
|
static ValueMap |
createFromResource(String resourceLocation)
|
|
static ValueMap |
createFromResource(String resourceLocation,
Class<?> searchStartPoint)
|
|
boolean |
doesNotContainKey(String key)
Returns true if the specified key is not present in this map. |
|
Value |
get(String key)
Retrieves the Value mapped to the specified key or
null if there is no such key. |
|
BigDecimal |
getBigDecimal(String key)
Returns the value stored under the specified required key as a BigDecimal. |
|
BigDecimal |
getBigDecimal(String key,
BigDecimal defaultValue)
Returns the value stored under the specified optional key as a BigDecimal. |
|
byte[] |
getBytes(String key)
Returns the value stored under the specified required key as a byte[]. |
|
byte[] |
getBytes(String key,
byte[] defaultValue)
Returns the value stored under the specified optional key as a byte[]. |
|
InputStream |
getBytesAsStream(String key)
Returns the value stored under the specified required key as an InputStream. |
|
InputStream |
getBytesAsStream(String key,
InputStream defaultValue)
Returns the value stored under the specified optional key as an InputStream. |
|
DateTime |
getDateTime(String key)
Returns the value stored under the specified required key as a DateTime (defaulting to the UTC timezone if necessary). |
|
DateTime |
getDateTime(String key,
DateTime defaultValue)
Returns the value stored under the specified optional key as a DateTime (defaulting to the UTC timezone if necessary). |
|
DateTime |
getDateTime(String key,
TimeZone tz)
Returns the value stored under the specified required key as a DateTime (defaulting to the specified timezone if necessary). |
|
DateTime |
getDateTime(String key,
TimeZone tz,
DateTime defaultValue)
Returns the value stored under the specified optional key as a DateTime (defaulting to the specified timezone if necessary). |
|
DateTime |
getDateTimeLocal(String key)
Returns the value stored under the specified required key as a DateTime (defaulting to the local VM's timezone if necessary). |
|
DateTime |
getDateTimeLocal(String key,
DateTime defaultValue)
Returns the value stored under the specified optional key as a DateTime (defaulting to the local VM's timezone if necessary). |
|
double |
getDouble(String key)
Returns the value stored under the specified required key as a double. |
|
double |
getDouble(String key,
double defaultValue)
Returns the value stored under the specified optional key as a double. |
|
Double |
getDoubleNumber(String key)
Returns the value stored under the specified required key as an Double. |
|
Double |
getDoubleNumber(String key,
Double defaultValue)
Returns the value stored under the specified optional key as an Double. |
|
float |
getFloat(String key)
Returns the value stored under the specified required key as a float. |
|
float |
getFloat(String key,
float defaultValue)
Returns the value stored under the specified optional key as a float. |
|
Float |
getFloatNumber(String key)
Returns the value stored under the specified required key as an Float. |
|
Float |
getFloatNumber(String key,
Float defaultValue)
Returns the value stored under the specified optional key as an Float. |
|
int |
getInt(String key)
Returns the value stored under the specified required key as an int. |
|
int |
getInt(String key,
int defaultValue)
Returns the value stored under the specified optional key as an int. |
|
Integer |
getIntegerNumber(String key)
Returns the value stored under the specified required key as an Integer. |
|
Integer |
getIntegerNumber(String key,
Integer defaultValue)
Returns the value stored under the specified optional key as an Integer. |
|
Object |
getLockObject()
Returns the object used for synchronization. |
|
long |
getLong(String key)
Returns the value stored under the specified required key as a long. |
|
long |
getLong(String key,
long defaultValue)
Returns the value stored under the specified optional key as a long. |
|
Long |
getLongNumber(String key)
Returns the value stored under the specified required key as a Long. |
|
Long |
getLongNumber(String key,
Long defaultValue)
Returns the value stored under the specified optional key as a Long. |
|
Map<String,Value> |
getMapView()
Returns a read-only view of all the mappings as a Map. |
|
ValueMap |
getNestedValueMap(String keyPrefix)
Returns a new ValueMap for all the key/value pairs with the specified key prefix (with the key prefix trimmed off). |
|
Number |
getNumber(String key)
Returns the value stored under the specified required key as a Number. |
|
Number |
getNumber(String key,
Number defaultValue)
Returns the value stored under the specified optional key as a Number. |
|
|
getObject(String key,
Class<T> type)
Returns the value stored under the specified required key as an Object. |
|
|
getObject(String key,
Class<T> type,
T defaultValue)
Returns the value stored under the specified optional key as an Object. |
|
Value |
getOptional(String key,
Value defaultValue)
Returns the Value mapped to the specified key or
if nothing is mapped to the key, defaultValue is returned. |
|
String[] |
getOrderedKeys()
Returns all the keys in the map in insertion order. |
|
PlainDate |
getPlainDate(String key)
Returns the value stored under the specified required key as a PlainDate. |
|
PlainDate |
getPlainDate(String key,
PlainDate defaultValue)
Returns the value stored under the specified optional key as a PlainDate. |
|
Properties |
getProperties()
Returns a copy of all the mappings as a Properties. |
|
Value |
getRequired(String key)
Returns the Value mapped to the specified key or
if nothing is mapped to the key,
ValueMapRequiredKeyException is thrown. |
|
int |
getSize()
Returns the number of entries in this ValueMap. |
|
String |
getString(String key)
Returns the value stored under the specified required key as a String. |
|
String |
getString(String key,
String defaultValue)
Returns the value stored under the specified optional key as a String. |
|
TriState |
getTriState(String key)
Returns the value stored under the specified required key as a TriState. |
|
TriState |
getTriState(String key,
TriState defaultValue)
Returns the value stored under the specified optional key as a TriState. |
|
boolean |
isTrue(String key)
Returns the value stored under the specified required key as a boolean. |
|
boolean |
isTrue(String key,
boolean defaultValue)
Returns the value stored under the specified optional key as a boolean. |
|
Value |
put(String key,
int value)
Stores (and possibly replaces) a key-value pair. |
|
Value |
put(String key,
long value)
Stores (and possibly replaces) a key-value pair. |
|
Value |
put(String key,
Number value)
Stores (and possibly replaces) a key-value pair. |
|
Value |
put(String key,
Object value)
Stores (and possibly replaces) a key-value pair. |
|
Value |
put(String key,
String value)
Stores (and possibly replaces) a key-value pair. |
|
Value |
put(String key,
Value value)
Stores (and possibly replaces) a key-value pair. |
|
void |
putAll(ValueMap source)
Copies all of the key-value pairs from the specified source ValueMap into this ValueMap. |
|
Value |
putPair(String keyValuePair)
Adds an entry to the map. |
|
Value |
remove(String key)
Removes the key-value pair stored under the specified key. |
|
String |
toString()
Returns a single-line textual approximation of values currently stored. |
|
String |
toStringMultiLine()
Returns a multi-line textual approximation of values currently stored as they would be written by writeTo(BufferedWriter). |
|
void |
writeTo(BufferedWriter out)
Writes the contents of the ValueMap out to the specified stream as text in key=value format. |
|
void |
writeTo(File file)
|
|
void |
writeTo(OutputStream out)
|
|
void |
writeTo(Writer out)
|
|
void |
writeToFile(String filename)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ValueMap(Object lock)
lock - the object to synchronize on, or null to
lock on this instance of ValueMap.public ValueMap()
| Method Detail |
|---|
public Object getLockObject()
ValueMap.
public int getSize()
public Value put(String key,
Value value)
throws ValueMapException
key - the name to use for subsequent retrieval of the value. If
key is null or a zero-length
String, a ValueMapException is
thrown. Leading and trailing whitespace on the key is NOT
trimmed before storage (using keys with leading and trailing
whitespace is highly discouraged anyway).value - the value mapped to the specified key. If the specified
value reference is null, a
Value will be created to wrap the null
[specifically, ValueFactory.NULL_INSTANCE is stored].
ValueMapException - if key is null
or a zero-length String.
public Value put(String key,
String value)
throws ValueMapException
key - the name to use for subsequent retrieval of the value. If
key is null or a zero-length
String, a ValueMapException is
thrown. Leading and trailing whitespace on the key is NOT
trimmed before storage (using keys with leading and trailing
whitespace is highly discouraged anyway).value - the value mapped to the specified key. If the specified
value reference is null, a
Value will be created to wrap the null
[specifically, ValueFactory.NULL_INSTANCE is stored].
ValueMapException - if key is null
or a zero-length String.
public Value put(String key,
Number value)
throws ValueMapException
key - the name to use for subsequent retrieval of the value. If
key is null or a zero-length
String, a ValueMapException is
thrown. Leading and trailing whitespace on the key is NOT
trimmed before storage (using keys with leading and trailing
whitespace is highly discouraged anyway).value - the value mapped to the specified key. If the specified
value reference is null, a
Value will be created to wrap the null
[specifically, ValueFactory.NULL_INSTANCE is stored].
ValueMapException - if key is null
or a zero-length String.
public Value put(String key,
int value)
throws ValueMapException
key - the name to use for subsequent retrieval of the value. If
key is null or a zero-length
String, a ValueMapException is
thrown. Leading and trailing whitespace on the key is NOT
trimmed before storage (using keys with leading and trailing
whitespace is highly discouraged anyway).value - the value mapped to the specified key.
ValueMapException - if key is null
or a zero-length String.
public Value put(String key,
long value)
throws ValueMapException
key - the name to use for subsequent retrieval of the value. If
key is null or a zero-length
String, a ValueMapException is
thrown. Leading and trailing whitespace on the key is NOT
trimmed before storage (using keys with leading and trailing
whitespace is highly discouraged anyway).value - the value mapped to the specified key.
ValueMapException - if key is null
or a zero-length String.
public Value put(String key,
Object value)
throws ValueMapException
key - the name to use for subsequent retrieval of the value. If
key is null or a zero-length
String, a ValueMapException is
thrown. Leading and trailing whitespace on the key is NOT
trimmed before storage (using keys with leading and trailing
whitespace is highly discouraged anyway).value - the value mapped to the specified key.
ValueMapException - if key is null
or a zero-length String.
public Value putPair(String keyValuePair)
throws ValueMapException
key=value
String supplied is treated like a line in a source file as described
in the general class description for this class.
ValueMapExceptionpublic void putAll(ValueMap source)
During the copy, the source's lock is held to prohibit modification to the source.
public boolean containsKey(String key)
Value is currently stored for the
specified key.
Any leading or trailing whitespace is first trimmed off of
the specified key.
public boolean doesNotContainKey(String key)
return !containsKey(key);
public boolean containsAnyKeyWithPrefix(String prefix)
public Value remove(String key)
key - the key to use for lookup.
Value previously stored, or null if
no match was found for the specified key.public Value get(String key)
Value mapped to the specified key or
null if there is no such key.
This method does not alter the mapping.
key - the key to use for lookup.
Value mapped to the specified key, or null
if nothing has been stored under the key.
public Value getOptional(String key,
Value defaultValue)
Value mapped to the specified key or
if nothing is mapped to the key, defaultValue is returned.
This method never returns null and this method does not
complain if the specified key is not found.
key - the key to use for lookup.defaultValue - the Value to return is there is no
mapping for the specified key.
Value mapped to the specified key, or
defaultValue if nothing has been stored under the key.
Never returns null (unless of course, the passed
defaultValue is null!).
public Value getRequired(String key)
throws ValueMapRequiredKeyException
Value mapped to the specified key or
if nothing is mapped to the key,
ValueMapRequiredKeyException is thrown.
This method never returns null: either a Value
is returned, or an exception is thrown if the specified key is not found.
The containsKey(String key) method can be used to
test before calling this method.
key - the required key to use for lookup.
Value mapped to the specified key.
Never returns null.
ValueMapRequiredKeyException - if the mapping does not
have a value stored for the specified key.
public String getString(String key)
throws ValueMapRequiredKeyException
ValueMapRequiredKeyException is thrown.
Equivalent to:
returngetRequired(key).getString();
ValueMapRequiredKeyException
public String getString(String key,
String defaultValue)
if (containsKey(key) ) { returnget(key).getString(); } else { return defaultValue; }
public <T> T getObject(String key,
Class<T> type)
throws ValueMapRequiredKeyException,
ValueException
ValueMapRequiredKeyException is thrown.
If the key does exist, but the Value stored under
it encapsulates null or an object of a type that can not be
cast into the specified type, a ValueException is
thrown. Equivalent to:
returngetRequired(key).getObject();
ValueMapRequiredKeyException
ValueException
public <T> T getObject(String key,
Class<T> type,
T defaultValue)
Value stored under
it encapsulates null or an object of a type that can not be
cast into the specified type, the specified
defaultValue is returned.
Equivalent to:
if (containsKey(key) ) { Value value = get(key); if ( value.isType(type) ) { return value.getObject(); } } return defaultValue;
public Number getNumber(String key)
throws ValueException,
ValueMapRequiredKeyException
Number. If the specified key does not exist, a
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as a
Number, then ValueException is thrown.
Equivalent to:
returngetRequired(key).getNumber();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the getNumber() method on Value if the looked up value can't be
interpreted as a Number.
public Number getNumber(String key,
Number defaultValue)
Number. If the specified key does not exist or if the
Value found can't be interpreted as a Number,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getNumber(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public BigDecimal getBigDecimal(String key)
throws ValueException,
ValueMapRequiredKeyException
BigDecimal. If the specified key does not exist, a
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as a
BigDecimal, then ValueException is thrown.
Equivalent to:
returngetRequired(key).getBigDecimal();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the
getBigDecimal() method on Value
if the looked up value can't be interpreted as a BigDecimal.
public BigDecimal getBigDecimal(String key,
BigDecimal defaultValue)
BigDecimal. If the specified key does not exist or if the
Value found can't be interpreted as a BigDecimal,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getBigDecimal(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public long getLong(String key)
throws ValueException,
ValueMapRequiredKeyException
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as a
long, the ValueException is thrown.
Equivalent to:
returngetRequired(key).getLong();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the getLong() method on Value if the looked up value can't be
interpreted as a long.
public long getLong(String key,
long defaultValue)
Value found can't be interpreted as a long,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getLong(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public Long getLongNumber(String key)
throws ValueException,
ValueMapRequiredKeyException
Long. If the specified key does not exist, a
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as a
Long, the ValueException is thrown.
Equivalent to:
returngetRequired(key).getLongNumber();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the getLongNumber() method on Value
if the looked up value can't be
interpreted as a Long.
public Long getLongNumber(String key,
Long defaultValue)
Long. If the specified key does not exist or if the
Value found can't be interpreted as a Long,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getLongNumber(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public int getInt(String key)
throws ValueException,
ValueMapRequiredKeyException
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as an
int, the ValueException is thrown.
Equivalent to:
returngetRequired(key).getInt();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the getInt() method on Value if the looked up value can't be
interpreted as an int.
public int getInt(String key,
int defaultValue)
Value found can't be interpreted as an int,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getInt(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public Integer getIntegerNumber(String key)
throws ValueException,
ValueMapRequiredKeyException
Integer. If the specified key does not exist, a
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as an
Integer, the ValueException is thrown.
Equivalent to:
returngetRequired(key).getIntegerNumber();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the getIntegerNumber() method on Value
if the looked up value can't be interpreted as an Integer.
public Integer getIntegerNumber(String key,
Integer defaultValue)
Integer. If the specified key does not exist or if the
Value found can't be interpreted as an Integer,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getIntegerNumber(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public double getDouble(String key)
throws ValueException,
ValueMapRequiredKeyException
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as a
double, the ValueException is thrown.
Equivalent to:
returngetRequired(key).getDouble();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the getDouble() method on Value if the looked up value can't be
interpreted as a double.
public double getDouble(String key,
double defaultValue)
Value found can't be interpreted as a double,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getDouble(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public Double getDoubleNumber(String key)
throws ValueException,
ValueMapRequiredKeyException
Double. If the specified key does not exist, a
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as an
Double, then ValueException is thrown.
Equivalent to:
returngetRequired(key).getDoubleNumber();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the getDoubleNumber() method on Value
if the looked up value can't be interpreted as an Double.
public Double getDoubleNumber(String key,
Double defaultValue)
Double. If the specified key does not exist or if the
Value found can't be interpreted as an Double,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getDoubleNumber(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public float getFloat(String key)
throws ValueException,
ValueMapRequiredKeyException
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as a
float, the ValueException is thrown.
Equivalent to:
returngetRequired(key).getFloat();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the getFloat() method on Value if the looked up value can't be
interpreted as a float.
public float getFloat(String key,
float defaultValue)
Value found can't be interpreted as a float,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getFloat(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public Float getFloatNumber(String key)
throws ValueException,
ValueMapRequiredKeyException
Float. If the specified key does not exist, a
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as an
Float, then ValueException is thrown.
Equivalent to:
returngetRequired(key).getFloatNumber();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the getFloatNumber() method on Value
if the looked up value can't be interpreted as an Float.
public Float getFloatNumber(String key,
Float defaultValue)
Float. If the specified key does not exist or if the
Value found can't be interpreted as an Float,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getFloatNumber(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public boolean isTrue(String key)
throws ValueMapRequiredKeyException
ValueMapRequiredKeyException is thrown.
Equivalent to:
returngetRequired(key).isTrue();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
public boolean isTrue(String key,
boolean defaultValue)
try {
return isTrue(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
}
public TriState getTriState(String key)
throws ValueMapRequiredKeyException
TriState.
If the specified key does not exist, a
ValueMapRequiredKeyException is thrown.
Equivalent to:
returngetRequired(key).getTriState();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
public TriState getTriState(String key,
TriState defaultValue)
TriState.
If the specified key does not exist,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getTriState(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
}
public DateTime getDateTime(String key)
throws ValueException,
ValueMapRequiredKeyException
DateTime (defaulting to the UTC timezone if necessary).
If the specified key does not exist, a
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as a
DateTime, then ValueException is thrown.
Equivalent to:
returngetRequired(key).getDateTime();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the getDateTime() method on Value if the looked up value can't be
interpreted as a DateTime.
public DateTime getDateTime(String key,
DateTime defaultValue)
DateTime (defaulting to the UTC timezone if necessary).
If the specified key does not exist or if the
Value found can't be interpreted as a DateTime,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getDateTime(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public DateTime getDateTimeLocal(String key)
throws ValueException,
ValueMapRequiredKeyException
DateTime (defaulting to the local VM's timezone if necessary).
If the specified key does not exist, a
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as a
DateTime, then ValueException is thrown.
Equivalent to:
returngetRequired(key).getDateTimeLocal();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the getDateTime() method on Value if the looked up value can't be
interpreted as a DateTime.
public DateTime getDateTimeLocal(String key,
DateTime defaultValue)
DateTime (defaulting to the local VM's timezone if necessary).
If the specified key does not exist or if the
Value found can't be interpreted as a DateTime,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getDateTime(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public DateTime getDateTime(String key,
TimeZone tz)
throws ValueException,
ValueMapRequiredKeyException
DateTime (defaulting to the specified timezone if necessary).
If the specified key does not exist, a
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as a
DateTime, then ValueException is thrown.
Equivalent to:
returngetRequired(key).getDateTime(tz);
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the getDateTime() method on Value if the looked up value can't be
interpreted as a DateTime.
public DateTime getDateTime(String key,
TimeZone tz,
DateTime defaultValue)
DateTime (defaulting to the specified timezone if necessary).
If the specified key does not exist or if the
Value found can't be interpreted as a DateTime,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getDateTime(key, tz);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public PlainDate getPlainDate(String key)
throws ValueException,
ValueMapRequiredKeyException
PlainDate.
If the specified key does not exist, a
ValueMapRequiredKeyException is thrown.
If the Value found can't be interpreted as a
PlainDate, then ValueException is thrown.
Equivalent to:
returngetRequired(key).getPlainDate();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
ValueException - passed along from the getPlainDate() method on Value if the looked up value can't be
interpreted as a PlainDate.
public PlainDate getPlainDate(String key,
PlainDate defaultValue)
PlainDate.
If the specified key does not exist or if the
Value found can't be interpreted as a PlainDate,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getPlainDate(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
} catch ( ValueException x ) {
return defaultValue;
}
public byte[] getBytes(String key)
throws ValueMapRequiredKeyException
ValueMapRequiredKeyException is thrown.
Equivalent to:
returngetRequired(key).getBytes();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
public byte[] getBytes(String key,
byte[] defaultValue)
try {
return getBytes(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
}
public InputStream getBytesAsStream(String key)
throws ValueMapRequiredKeyException
InputStream.
If the specified key does not exist, a
ValueMapRequiredKeyException is thrown.
Equivalent to:
returngetRequired(key).getBytesAsStream();
ValueMapRequiredKeyException - if the key is
not present in this mapping.
public InputStream getBytesAsStream(String key,
InputStream defaultValue)
InputStream.
If the specified key does not exist,
then the specified defaultValue is returned.
Equivalent to (although it may be implemented more efficiently):
try {
return getBytesAsStream(key);
} catch ( ValueMapRequiredKeyException x ) {
return defaultValue;
}
public String[] getOrderedKeys()
public Map<String,Value> getMapView()
Map.
public Properties getProperties()
Properties.
The Properties object returned is a snapshot of the
mappings as of the time this method is called—there is
no linkage between this ValueMap and the newly created
Properties object. All keys in this map are already
restricted to being only String's. All values in this
map are interpreted using getString(key)
to create the String to be placed into the Properties
instance returned.
public ValueMap getNestedValueMap(String keyPrefix)
Value's are shared (not copied) as most
implementations of Value are immutable (if you have
mutable Value's in your map you may need to be careful).
If no keys match the prefix, then an empty ValueMap
(with zero entries) is returned.
For example, consider starting with the following file to populate a ValueMap:
solar.system.Mercury.diameter=0.38 solar.system.Venus.diameter=0.95 solar.system.Earth.diameter=1.00 solar.system.Mars.diameter=0.53 solar.system.Jupiter.diameter=11.2 solar.system.Mercury.mass=0.06 solar.system.Venus.mass=0.82 solar.system.Earth.mass=1.00 solar.system.Mars.mass=0.11 solar.system.Jupiter.mass=318 solar.system.Mercury.moon.count=0 solar.system.Venus.moon.count=0 solar.system.Earth.moon.count=1 solar.system.Mars.moon.count=2 solar.system.Jupiter.moon.count=63 country.usa.full.name=United States country.usa.capital=Washington, DC country.can.full.name=Canada country.can.capital=Ottawa country.gbr.full.name=United Kingdom country.gbr.capital=London country.swe.full.name=Sweden country.swe.capital=Stockholm country.nor.full.name=Norway country.nor.capital=Oslo country.che.full.name=Switzerland country.che.capital=BernThe new ValueMap created by:
ValueMap countryMap = map.getNestedValueMap("country.");
would be:
usa.full.name=United States usa.capital=Washington, DC can.full.name=Canada can.capital=Ottawa gbr.full.name=United Kingdom gbr.capital=London swe.full.name=Sweden swe.capital=Stockholm nor.full.name=Norway nor.capital=Oslo che.full.name=Switzerland che.capital=Bernfrom that map, if someone did this:
ValueMap usaMap = countryMap.getNestedValueMap("usa.");
the result would be:
full.name=United States capital=Washington, DC
Going back to the original, the new ValueMap created by:
ValueMap solarMap = map.getNestedValueMap("solar.system.");
would be:
Mercury.diameter=0.38 Venus.diameter=0.95 Earth.diameter=1.00 Mars.diameter=0.53 Jupiter.diameter=11.2 Mercury.mass=0.06 Venus.mass=0.82 Earth.mass=1.00 Mars.mass=0.11 Jupiter.mass=318 Mercury.moon.count=0 Venus.moon.count=0 Earth.moon.count=1 Mars.moon.count=2 Jupiter.moon.count=63from that map, if someone did this:
ValueMap marsMap = solarMap.getNestedValueMap("Mars.");
the result would be:
diameter=0.53 mass=0.11 moon.count=2
keyPrefix - specifies the subset of keys to match. Matched keys
must start with this prefix and then must have at least one remaining
character.public String toString()
toStringMultiLine().
The returned string looks something like:
"{key1=value1, key2=value2, key3=, key4=value4}"
toString in class Objectpublic String toStringMultiLine()
writeTo(BufferedWriter).
To get in a single-line format, call toString().
public void writeTo(BufferedWriter out)
throws ValueMapException
out - destination for the key=value pairs.
ValueMapException - if there are any troubles writing out to the
stream.
public void writeTo(Writer out)
throws ValueMapException
ValueMapException
public void writeTo(OutputStream out)
throws ValueMapException
ValueMapException
public void writeTo(File file)
throws ValueMapException
ValueMapException
public void writeToFile(String filename)
throws ValueMapException
ValueMapExceptionpublic static ValueMap createFrom(Map<?,?> map)
Map into a new
ValueMap. Each key in the map is passed to the
String.valueOf(Object) method
to generate the string-based key
needed by ValueMap. Each value is simply passed to
create(Object obj) method on
ValueFactory.
map - source of key/value pairs
ValueMapException
public static ValueMap createFrom(BufferedReader in)
throws ValueMapException
in - source of data; always closed by this method.
ValueMapException - if there are problems reading
from the stream, or if an line it improperly formatted.
public static ValueMap createFrom(Reader rawIn)
throws ValueMapException
rawIn - source of data; always closed by this method.
ValueMapException - if there are problems reading
from the stream, or if an line it improperly formatted.
public static ValueMap createFrom(InputStream rawIn)
throws ValueMapException
ValueMapException
public static ValueMap createFrom(File source)
throws ValueMapException
ValueMapException
public static ValueMap createFromFile(String sourceFilename)
throws ValueMapException
ValueMapException
public static ValueMap createFrom(URL source)
throws ValueMapException
ValueMapException
public static ValueMap createFromResource(String resourceLocation,
Class<?> searchStartPoint)
throws ValueMapException
ValueMapException
public static ValueMap createFromResource(String resourceLocation)
throws ValueMapException
ValueMapException
|
ProgramixGenericLib v5.0.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||