|
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.AbstractValue
public abstract class AbstractValue
A simple partial implementation of Value
.
See Value
for a full explanation of all of the methods.
Check out ValueFactory
to see if there is a create method
available that might eliminate your need to extend AbstractValue.
Check out ValueMap
for key-value mappings, reading and writing
to files and other streams, and more.
Constructor Summary | |
---|---|
protected |
AbstractValue()
This constructor is protected because it only makes sense to be called from a subclass as AbstractValue is not a concrete class (it's abstract after all). |
Method Summary | ||
---|---|---|
BigDecimal |
getBigDecimal()
Returns the result as a BigDecimal . |
|
BigDecimal |
getBigDecimalOrNull()
Returns the result as a BigDecimal
or null if the value is empty. |
|
byte |
getByte()
Returns the result as a rounded off byte value. |
|
Byte |
getByteNumber()
Returns the result as a rounded off Byte value. |
|
Byte |
getByteNumberOrNull()
Returns the result as a Byte
or null if the value is empty. |
|
byte[] |
getBytes()
Returns the encapsulated value interpreted as a byte[]. |
|
InputStream |
getBytesAsStream()
Returns the encapsulated value interpreted as bytes that are readable from InputStream . |
|
DateTime |
getDateTime()
Returns the encapsulated value interpreted as a DateTime
assuming the UTC timezone if necessary. |
|
DateTime |
getDateTime(TimeZone defaultTimeZone)
Returns the encapsulated value interpreted as a DateTime
assuming the specified timezone if necessary. |
|
DateTime |
getDateTimeLocal()
Returns the encapsulated value interpreted as a DateTime
assuming the local VM's timezone if necessary. |
|
DateTime |
getDateTimeLocalOrNull()
Returns the result as a DateTime
or null if the value is empty
(using the local VM's timezone for interpretation if necessary). |
|
DateTime |
getDateTimeOrNull()
Returns the result as a DateTime
or null if the value is empty
(using the UTC timezone for interpretation if necessary). |
|
DateTime |
getDateTimeOrNull(TimeZone defaultTimeZone)
Returns the result as a DateTime
or null if the value is empty
(using the specified timezone for interpretation if necessary). |
|
double |
getDouble()
Returns the result as a double value. |
|
Double |
getDoubleNumber()
Returns the result as a Double value. |
|
Double |
getDoubleNumberOrNull()
Returns the result as an Double
or null if the value is empty. |
|
float |
getFloat()
Returns the result as a float value. |
|
Float |
getFloatNumber()
Returns the result as a Float value. |
|
Float |
getFloatNumberOrNull()
Returns the result as an Float
or null if the value is empty. |
|
int |
getInt()
Returns the result as a rounded off int value. |
|
Integer |
getIntegerNumber()
Returns the result as a rounded off Integer value. |
|
Integer |
getIntegerNumberOrNull()
Returns the result as an Integer
or null if the value is empty. |
|
long |
getLong()
Returns the result as a rounded off long value. |
|
Long |
getLongNumber()
Returns the result as a rounded off Long value. |
|
Long |
getLongNumberOrNull()
Returns the result as a Long
or null if the value is empty. |
|
Number |
getNumber()
Returns the encapsulated value interpreted a Number value. |
|
Number |
getNumberOrNull()
Returns the result as a Number
or null if the value is empty. |
|
abstract Object |
getObject()
Returns the encapsulated value as a generic Object reference. |
|
|
getObject(Class<T> targetType)
Returns the encapsulated value as a generic Object reference that is guaranteed to be able to be explicitly cast into the specified targetType . |
|
|
getObjectOrNull(Class<T> targetType)
Returns the encapsulated value as a generic Object reference or null if the value is empty. |
|
PlainDate |
getPlainDate()
Returns the encapsulated value interpreted as a PlainDate . |
|
PlainDate |
getPlainDateOrNull()
Returns the result as a PlainDate
or null if the value is empty. |
|
String |
getRawString()
Returns the encapsulated value as a String value without trimming leading and trailing whitespace. |
|
short |
getShort()
Returns the result as a rounded off short value. |
|
Short |
getShortNumber()
Returns the result as a rounded off Short value. |
|
Short |
getShortNumberOrNull()
Returns the result as a Short
or null if the value is empty. |
|
String |
getString()
Returns the encapsulated value as a String value after trimming leading and trailing whitespace. |
|
String |
getStringOrNull()
Returns the result as a String
or null if the value is empty. |
|
TriState |
getTriState()
Returns the encapsulated value interpreted as a TriState . |
|
boolean |
isDateTime()
Returns true if this value is, or if it can be interpreted as, a DateTime . |
|
boolean |
isEmpty()
Returns true if the encapsulated value is either null, a zero-length String, or a String of all whitespace. |
|
boolean |
isFalse()
Returns true if the encapsulated value can not be interpreted as something considered to be "true". |
|
boolean |
isMutable()
Returns true if the public view of this Value might change over time. |
|
boolean |
isNotDateTime()
Returns true if the encapsulated value can not be interpreted as a DateTime value. |
|
boolean |
isNotEmpty()
Returns true if the encapsulated value is NOT empty. |
|
boolean |
isNotNull()
Returns true if the encapsulated value is NOT null. |
|
boolean |
isNotNumeric()
Returns true if the encapsulated value can not be interpreted as a numeric value. |
|
boolean |
isNotPlainDate()
Returns true if the encapsulated value can not be interpreted as a PlainDate value. |
|
boolean |
isNotType(Class<?> targetType)
Returns true if the result of getObject()
is null or can not be cast into the
specified type. |
|
boolean |
isNotTypeByteArray()
Returns true if the result of getObject()
is not an object of the type byte[]. |
|
boolean |
isNotTypeDateTime()
Returns true if the result of getObject()
is not an object of the type DateTime . |
|
boolean |
isNotTypeNumber()
Returns true if the result of getObject()
is not an object of the type Number . |
|
boolean |
isNotTypePlainDate()
Returns true if the result of getObject()
is not an object of the type PlainDate . |
|
boolean |
isNull()
Returns true if the encapsulated value is null. |
|
boolean |
isNumeric()
Returns true if the encapsulated value can be interpreted as a number. |
|
boolean |
isPlainDate()
Returns true if this value is, or if it can be interpreted as, a PlainDate . |
|
boolean |
isTrue()
Returns the result as a boolean value. |
|
boolean |
isType(Class<?> targetType)
Returns true if the result of getObject()
is not null and can be cast into the specified type. |
|
boolean |
isTypeByteArray()
Returns true if the result of getObject()
is not null and can be cast to the type byte[]. |
|
boolean |
isTypeDateTime()
Returns true if the result of getObject()
is not null and can be cast to the type DateTime . |
|
boolean |
isTypeNumber()
Returns true if the result of getObject()
is not null and can be cast to the type Number . |
|
boolean |
isTypePlainDate()
Returns true if the result of getObject()
is not null and can be cast to the type PlainDate . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected AbstractValue()
Method Detail |
---|
public abstract Object getObject()
Value
isType(Class target)
method can be used to
test the type first, if desired).
If the value stored internally is null, then null
will be returned.
getObject
in interface Value
public <T> T getObject(Class<T> targetType) throws ValueException, IllegalArgumentException
Value
targetType
.
If the internal value is not of the specified
type, a ValueException
is thrown with details in its
message about the actual type of the internal object.
If the value stored internally is null, then a
ValueException
will be thrown.
Equivalent to:
if (isNotType
(targetType) ) { throw new ValueException( //... } returngetObject
();
getObject
in interface Value
targetType
- type to check against, must not be null.
ValueException
- if the encapsulated value is not of the
specified type, or if it is null
.
IllegalArgumentException
- if targetType is null.public <T> T getObjectOrNull(Class<T> targetType) throws ValueException, IllegalArgumentException
Value
targetType
(note: null
can be cast into any type).
If the internal value is not empty and is not of the specified
type, a ValueException
is thrown with details in its
message about the actual type of the internal object.
Equivalent to:
if (isEmpty()
) { return null; } else { returngetObject(targetType)
; }
getObjectOrNull
in interface Value
targetType
- type to check against, must not be null.
ValueException
- if the encapsulated value is not empty and
is not of the specified type.
IllegalArgumentException
- if targetType is null.
Note that ValueException and IllegalArgumentException
are both a RuntimeException
so neither has to be explicitly caught.public boolean isNull()
Value
return getObject()
== null;
isNull
in interface Value
public boolean isNotNull()
Value
return !isNull()
;
isNotNull
in interface Value
public boolean isEmpty()
Value
returnisNull()
|| (getString()
.length() == 0);
isEmpty
in interface Value
public boolean isNotEmpty()
Value
isEmpty()
for an explanation of empty.
Equivalent to:
return !isEmpty()
;
isNotEmpty
in interface Value
public boolean isType(Class<?> targetType) throws IllegalArgumentException
Value
getObject()
is not null and can be cast into the specified type.
isType
in interface Value
IllegalArgumentException
- if targetType is null.public boolean isNotType(Class<?> targetType) throws IllegalArgumentException
Value
getObject()
is null or can not be cast into the
specified type.
Equivalent to:
return !isType
(targetType);
isNotType
in interface Value
IllegalArgumentException
- if targetType is null.public boolean isTypeNumber()
Value
getObject()
is not null and can be cast to the type Number
.
Number
is the abstract superclass of
Byte
, Short
, Integer
, Long
,
Float
, Double
, BigDecimal
,
and BigInteger
.
This method's test is stricter than Value.isNumeric()
(which
checks to see if there is any way to interpret the value as a
number).
Equivalent to:
returnisNotNull()
&& (getObject()
instanceof Number);
isTypeNumber
in interface Value
public boolean isNotTypeNumber()
Value
getObject()
is not an object of the type Number
.
Equivalent to:
return !isTypeNumber()
;
isNotTypeNumber
in interface Value
public boolean isTypeDateTime()
Value
getObject()
is not null and can be cast to the type DateTime
.
This method's test is stricter than Value.isDateTime()
(which
checks to see if there is any way to interpret the value as a
DateTime).
Equivalent to:
returnisNotNull()
&& (getObject()
instanceofDateTime
);
isTypeDateTime
in interface Value
public boolean isNotTypeDateTime()
Value
getObject()
is not an object of the type DateTime
.
Equivalent to:
return !isTypeDateTime()
;
isNotTypeDateTime
in interface Value
public boolean isTypePlainDate()
Value
getObject()
is not null and can be cast to the type PlainDate
.
This method's test is stricter than Value.isPlainDate()
(which
checks to see if there is any way to interpret the value as a
PlainDate).
Equivalent to:
returnisNotNull()
&& (getObject()
instanceofPlainDate
);
isTypePlainDate
in interface Value
public boolean isNotTypePlainDate()
Value
getObject()
is not an object of the type PlainDate
.
Equivalent to:
return !isTypePlainDate()
;
isNotTypePlainDate
in interface Value
public boolean isTypeByteArray()
Value
getObject()
is not null and can be cast to the type byte[].
This method's test is stricter than Value.getBytes()
and
Value.getBytesAsStream()
(they always find a way to interpret the value as a byte[]).
Equivalent to:
returnisNotNull()
&& (getObject()
instanceof byte[]);
isTypeByteArray
in interface Value
public boolean isNotTypeByteArray()
Value
getObject()
is not an object of the type byte[].
Equivalent to:
return !isTypeByteArray()
;
isNotTypeByteArray
in interface Value
public String getString()
Value
Object obj = getObject()
;
return (obj == null) ? "" : obj.toString().trim();
getString
in interface Value
public String getStringOrNull()
Value
String
or null if the value is empty.
Note that this method returns null if the value is
null, a zero-length string, or a string of all whitespace; a
string is only returned if there are non-whitespace characters
available. Look carefully at Value.isEmpty()
and Value.getString()
.
Equivalent to:
if (isEmpty()
) { return null; } else { returngetString()
; }
getStringOrNull
in interface Value
public String getRawString()
Value
Object obj = getObject()
;
return (obj == null) ? "" : obj.toString();
getRawString
in interface Value
public boolean isNumeric()
Value
getNumber()
can be called without
a throwing a ValueException
, isNumeric returns
true. See Value.getNumber()
for details.
This method's test is more lenient than Value.isTypeNumber()
(which
only checks to see if the encapsulated object is a subclass of
Number
).
Equivalent to (although typically implemented more efficiently):
try {
getNumber
();
return true;
} catch ( ValueException x ) {
return false;
}
isNumeric
in interface Value
public boolean isNotNumeric()
Value
isNumeric()
for an explanation of how
numeric is determined.
Equivalent to:
return !isNumeric
();
isNotNumeric
in interface Value
public Number getNumber() throws ValueException
Value
Number
,
the value is simply returned.DateTime
,
a new Long
is wrapped around the long returned by
getTime()
.getString()
is run through StringTools.winnowDecimal()
and the result can be successfully parsed
by the constructor of BigDecimal
,
then that BigDecimal is returned.Equivalent to:
Object obj =NOTE: if you really need a BigDecimal, then callgetObject
(); if ( obj instanceof Number ) { return (Number) obj; } else if ( obj instanceof DateTime ) { DateTime dateTime = (DateTime) obj; return new Long(dateTime.getTime()); } else if ( obj == null ) { throw new ValueException(//... } try { return newBigDecimal
(StringTools.winnowDecimal
(getString
())); } catch ( NumberFormatException x ) { throw new ValueException(x); }
getBigDecimal()
instead.
getNumber
in interface Value
ValueException
- if the encapsulated value can not
be interpreted as a numeric value.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public Number getNumberOrNull() throws ValueException
Value
Number
or null if the value is empty.
Equivalent to:
if (isEmpty()
) { return null; } else { returngetNumber()
; }
getNumberOrNull
in interface Value
ValueException
- if the value is not empty and can not
be interpreted as a numeric value.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public BigDecimal getBigDecimal() throws ValueException
Value
BigDecimal
. Equivalent to:
Number num = getNumber()
;
if ( num instanceof BigDecimal ) {
return (BigDecimal) num;
}
try {
return new BigDecimal(num.toString());
} catch ( NumberFormatException x ) {
throw new ValueException( //...
}
getBigDecimal
in interface Value
ValueException
- if the value is null or can not be
viewed as a BigDecimal
.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public BigDecimal getBigDecimalOrNull() throws ValueException
Value
BigDecimal
or null if the value is empty.
Equivalent to:
if (isEmpty()
) { return null; } else { returngetBigDecimal()
; }
getBigDecimalOrNull
in interface Value
ValueException
- if the value is not empty and can not be
viewed as a BigDecimal
.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public long getLong() throws RangeValueException, ValueException
Value
return NumberTools.toLong
(getNumber()
);
getLong
in interface Value
RangeValueException
- if the value does not fit in
the range of valid long values.
ValueException
- if the value can not be
interpreted as a numeric value.Value.getLongNumber()
public Long getLongNumber() throws RangeValueException, ValueException
Value
Long
value.
Equivalent to:
return NumberTools.toLongNumber
(getNumber()
);
getLongNumber
in interface Value
RangeValueException
- if the value does not fit in
the range of valid long values.
ValueException
- if the value can not be
interpreted as a numeric value.Value.getLong()
public Long getLongNumberOrNull() throws RangeValueException, ValueException
Value
Long
or null if the value is empty.
Equivalent to:
if (isEmpty()
) { return null; } else { returngetLongNumber()
; }
getLongNumberOrNull
in interface Value
RangeValueException
- if the value does not fit in
the range of valid long values.
ValueException
- if the value is not empty and can not be
viewed as a Long
.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public int getInt() throws RangeValueException, ValueException
Value
return NumberTools.toInt
(getNumber()
);
getInt
in interface Value
RangeValueException
- if the value does not fit in
the range of valid int values.
ValueException
- if the value can not be
interpreted as a numeric value.Value.getIntegerNumber()
public Integer getIntegerNumber() throws RangeValueException, ValueException
Value
Integer
value.
Equivalent to:
return NumberTools.toIntegerNumber
(getNumber()
);
getIntegerNumber
in interface Value
RangeValueException
- if the value does not fit in
the range of valid int values.
ValueException
- if the value can not be
interpreted as a numeric value.Value.getInt()
public Integer getIntegerNumberOrNull() throws RangeValueException, ValueException
Value
Integer
or null if the value is empty.
Equivalent to:
if (isEmpty()
) { return null; } else { returngetIntegerNumber()
; }
getIntegerNumberOrNull
in interface Value
RangeValueException
- if the value does not fit in
the range of valid int values.
ValueException
- if the value is not empty and can not be
viewed as a Integer
.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public short getShort() throws RangeValueException, ValueException
Value
return NumberTools.toShort
(getNumber()
);
getShort
in interface Value
RangeValueException
- if the value does not fit in
the range of valid short values.
ValueException
- if the value can not be
interpreted as a numeric value.Value.getShortNumber()
public Short getShortNumber() throws RangeValueException, ValueException
Value
Short
value.
Equivalent to:
return NumberTools.toShortNumber
(getNumber()
);
getShortNumber
in interface Value
RangeValueException
- if the value does not fit in
the range of valid short values.
ValueException
- if the value can not be
interpreted as a numeric value.Value.getShort()
public Short getShortNumberOrNull() throws RangeValueException, ValueException
Value
Short
or null if the value is empty.
Equivalent to:
if (isEmpty()
) { return null; } else { returngetShortNumber()
; }
getShortNumberOrNull
in interface Value
RangeValueException
- if the value does not fit in
the range of valid short values.
ValueException
- if the value is not empty and can not be
viewed as a Short
.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public byte getByte() throws RangeValueException, ValueException
Value
return NumberTools.toByte
(getNumber()
);
getByte
in interface Value
RangeValueException
- if the value does not fit in
the range of valid byte values.
ValueException
- if the value can not be
interpreted as a numeric value.Value.getByteNumber()
public Byte getByteNumber() throws RangeValueException, ValueException
Value
Byte
value.
Equivalent to:
return NumberTools.toByteNumber
(getNumber()
);
getByteNumber
in interface Value
RangeValueException
- if the value does not fit in
the range of valid byte values.
ValueException
- if the value can not be
interpreted as a numeric value.Value.getByte()
public Byte getByteNumberOrNull() throws RangeValueException, ValueException
Value
Byte
or null if the value is empty.
Equivalent to:
if (isEmpty()
) { return null; } else { returngetByteNumber()
; }
getByteNumberOrNull
in interface Value
RangeValueException
- if the value does not fit in
the range of valid byte values.
ValueException
- if the value is not empty and can not be
viewed as a Byte
.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public double getDouble() throws ValueException
Value
returngetNumber()
.doubleValue
();
getDouble
in interface Value
ValueException
- if the string can not be
parsed into a numeric value.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public Double getDoubleNumber() throws ValueException
Value
Double
value.
Equivalent to:
return new Double(getDouble()
);
getDoubleNumber
in interface Value
ValueException
- if the value can not be
interpreted as a numeric value.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.Value.getDouble()
public Double getDoubleNumberOrNull() throws ValueException
Value
Double
or null if the value is empty.
Equivalent to:
if (isEmpty()
) { return null; } else { returngetDoubleNumber()
; }
getDoubleNumberOrNull
in interface Value
ValueException
- if the value is not empty and can not be
viewed as a Double
.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public float getFloat() throws ValueException
Value
returngetNumber()
.floatValue
();
getFloat
in interface Value
ValueException
- if the string can not be
parsed into a numeric value.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public Float getFloatNumber() throws ValueException
Value
Float
value.
Equivalent to:
return new Float(getFloat()
);
getFloatNumber
in interface Value
ValueException
- if the value can not be
interpreted as a numeric value.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.Value.getFloat()
public Float getFloatNumberOrNull() throws ValueException
Value
Float
or null if the value is empty.
Equivalent to:
if (isEmpty()
) { return null; } else { returngetFloatNumber()
; }
getFloatNumberOrNull
in interface Value
ValueException
- if the value is not empty and can not be
viewed as a Float
.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public boolean isTrue()
Value
getString()
matches (case-insensitively) any one of the following:
true, t, yes, y, on, 1
isTrue
in interface Value
public boolean isFalse()
Value
isTrue()
for an explanation of how
"true" is interpreted. This method can be thought of more as a
"is not true" as opposed to confirming that something is "false"
(for example, blank and null are consider to be "not true").
Equivalent to:
return !isTrue
();
isFalse
in interface Value
public TriState getTriState()
Value
TriState
.
More specifically:
TriState
,
the value is simply returned.TriState.UNKNOWN
is returned.Boolean
and that Boolean is holding true, then
TriState.YES
is returned.Boolean
and that Boolean is holding false, then
TriState.NO
is returned.getString()
matches (case-insensitively) any one of the following:
"yes", "y", "true", "t",
"on", or "1",
then TriState.YES
is returned.getString()
matches (case-insensitively) any one of the following:
"no", "n", "false", "f",
"off", or "0",
then TriState.NO
is returned.TriState.UNKNOWN
is returned.TriState
,
null is never returned.
Equivalent to:
Object obj =getObject
(); if ( obj instanceofTriState
) { return (TriState) obj; } else if ( obj == null ) { return TriState.UNKNOWN
; } else if ( obj instanceof Boolean ) { if ( ((Boolean) obj).booleanValue() == true ) { return TriState.YES
; } else { return TriState.NO
; } } String s =getString
(); if ( "yes".equalsIgnoreCase(s) || "y".equalsIgnoreCase(s) || "true".equalsIgnoreCase(s) || "t".equalsIgnoreCase(s) || "on".equalsIgnoreCase(s) || "1".equals(s) ) { return TriState.YES
; } if ( "no".equalsIgnoreCase(s) || "n".equalsIgnoreCase(s) || "false".equalsIgnoreCase(s) || "f".equalsIgnoreCase(s) || "off".equalsIgnoreCase(s) || "0".equals(s) ) { return TriState.NO
; } return TriState.UNKNOWN
;
getTriState
in interface Value
public boolean isDateTime()
Value
DateTime
.
Specifically, true is returned if calling
Value.getDateTime()
will not result in an exception being thrown.
isDateTime
in interface Value
public boolean isNotDateTime()
Value
DateTime
value.
See getDateTime()
for an explanation of how
DateTime is determined.
Equivalent to:
return !isDateTime
();
isNotDateTime
in interface Value
public DateTime getDateTime() throws ValueException
Value
DateTime
assuming the UTC timezone if necessary.
More specifically:
DateTime
,
the value is simply returned.
The default timezone of UTC is neither needed nor used.getString()
can be successfully parsed by the
DateTools.parseUTC(String)
method, the resulting
DateTime is returned, if not, a ValueException
is thrown instead.Equivalent to:
Object obj =getObject
(); if ( obj instanceofDateTime
) { return (DateTime) obj; } try { return DateTools.parseUTC
(getString
()); } catch ( DateTimeException x ) { throw new ValueException(x); }
getDateTime
in interface Value
ValueException
- if the encapsulated value is
null or if it is not a instance of DateTime and the
result of getString() can not be parsed into a DateTime.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public DateTime getDateTimeOrNull() throws ValueException
Value
DateTime
or null if the value is empty
(using the UTC timezone for interpretation if necessary).
Equivalent to:
if (isEmpty()
) { return null; } else { returngetDateTime()
; }
getDateTimeOrNull
in interface Value
ValueException
- if the value is not empty and can not be
viewed as a DateTime
.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public DateTime getDateTimeLocal() throws ValueException
Value
DateTime
assuming the local VM's timezone if necessary.
More specifically:
DateTime
,
the value is simply returned.
The default timezone of the local VM is neither needed nor used.getString()
can be successfully parsed by the
DateTools.parseLocal(String)
method, the resulting
DateTime is returned, if not, a ValueException
is thrown instead.Equivalent to:
Object obj =getObject
(); if ( obj instanceof DateTime ) { return (DateTime) obj; } try { return DateTools.parseLocal
(getString
()); } catch ( DateTimeException x ) { throw new ValueException(x); }
getDateTimeLocal
in interface Value
ValueException
- if the encapsulated value is
null or if it is not a instance of DateTime and the
result of getString() can not be parsed into a DateTime.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public DateTime getDateTimeLocalOrNull() throws ValueException
Value
DateTime
or null if the value is empty
(using the local VM's timezone for interpretation if necessary).
Equivalent to:
if (isEmpty()
) { return null; } else { returngetDateTimeLocal()
; }
getDateTimeLocalOrNull
in interface Value
ValueException
- if the value is not empty and can not be
viewed as a DateTime
.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public DateTime getDateTime(TimeZone defaultTimeZone) throws ValueException, IllegalArgumentException
Value
DateTime
assuming the specified timezone if necessary.
More specifically:
DateTime
,
the value is simply returned.
The timezone passed in is neither needed nor used.getString()
can be successfully parsed by the
DateTools.parse(String, TimeZone)
method, the resulting
DateTime is returned, if not, a ValueException
is thrown instead.Equivalent to:
Object obj =getObject
(); if ( obj instanceof DateTime ) { return (DateTime) obj; } try { return DateTools.parse
(getString
(), defaultTimeZone); } catch ( DateTimeException x ) { throw new ValueException(x); }
getDateTime
in interface Value
defaultTimeZone
- the timezone to use to interpret the value
as a DateTime if necessary.
ValueException
- if the encapsulated value is
null or if it is not a instance of DateTime and the
result of getString() can not be parsed into a DateTime.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.
IllegalArgumentException
- if defaultTimeZone
is null.public DateTime getDateTimeOrNull(TimeZone defaultTimeZone) throws ValueException, IllegalArgumentException
Value
DateTime
or null if the value is empty
(using the specified timezone for interpretation if necessary).
Equivalent to:
if (isEmpty()
) { return null; } else { returngetDateTime(defaultTimeZone)
; }
getDateTimeOrNull
in interface Value
ValueException
- if the value is not empty and can not be
viewed as a DateTime
.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.
IllegalArgumentException
- if defaultTimeZone
is null.public boolean isPlainDate()
Value
PlainDate
.
Specifically, true is returned if calling
Value.getPlainDate()
will not result in an exception being thrown.
isPlainDate
in interface Value
public boolean isNotPlainDate()
Value
PlainDate
value.
See getPlainDate()
for an explanation of how
PlainDate is determined.
Equivalent to:
return !isPlainDate
();
isNotPlainDate
in interface Value
public PlainDate getPlainDate() throws ValueException
Value
PlainDate
.
More specifically:
PlainDate
,
the value is simply returned.getString()
can be successfully parsed by the
DateTools.parsePlainDate(String)
method, the resulting
PlainDate is returned, if not, a ValueException
is thrown instead.Equivalent to:
Object obj =getObject
(); if ( obj instanceofPlainDate
) { return (PlainDate) obj; } try { return DateTools.parsePlainDate
(getString
()); } catch ( PlainDateException x ) { throw new ValueException(x); }
getPlainDate
in interface Value
ValueException
- if the encapsulated value is
null or if it is not a instance of PlainDate and the
result of getString() can not be parsed into a PlainDate.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public PlainDate getPlainDateOrNull() throws ValueException
Value
PlainDate
or null if the value is empty.
Equivalent to:
if (isEmpty()
) { return null; } else { returngetPlainDate()
; }
getPlainDateOrNull
in interface Value
ValueException
- if the value is not empty and can not be
viewed as a PlainDate
.
Note that ValueException is a RuntimeException
so it does not have to be explicitly caught.public byte[] getBytes()
Value
Value.getString()
is passed through
StringTools.parseHexString(String)
.
Equivalent to:
Object obj =getObject()
; if ( obj instanceof byte[] ) { return (byte[]) ((byte[]) obj).clone(); } return StringTools.parseHexString
(getString
());
The byte[] returned
is a copy of the internal data, so there is no chance that an
outsider could manipulate the bytes held internally. To avoid making
copies of large amounts of data, you may want to consider
using Value.getBytesAsStream()
instead.
getBytes
in interface Value
Value.getBytesAsStream()
public InputStream getBytesAsStream()
Value
InputStream
.
Internally, the byte[] that serves as a data source for an
InputStream
is byte[] derived by Value.getBytes()
(however, there is no need to make a copy of the internal
byte[] as the InputStream provides no mechanism
for altering the source of the data). Every call to this method
returns a new lightweight InputStream that can be independently
read, but the bulky byte[] is efficiently shared among all of
the InputStream's that are constructed.
This method is a more memory efficient than calling Value.getBytes()
as no copy of the binary data needs to be made.
Equivalent to:
Object obj =getObject()
; if ( obj instanceof byte[] ) { return new ByteArrayInputStream((byte[]) obj); } return new ByteArrayInputStream( StringTools.parseHexString
(getString
()));
getBytesAsStream
in interface Value
Value.getBytes()
public boolean isMutable()
Value
If implementors of Value want to use internal caching for efficiency, they are free to return false from isMutable() as long as the return values for all of the non-private methods never change.
Ironically, the return value from this method must be fixed at the time of construction and may never change. If this method ever returns false is must continue to return false during any subsequent calls.
isMutable
in interface Value
|
ProgramixGenericLib v5.0.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |