Interface IValueObject<TYPE>
- All Known Implementing Classes:
BigDecimalValue
,BigIntegerValue
,BinaryValue
,BooleanValue
,ByteValue
,DoubleValue
,DurationValue
,FloatValue
,IntegerValue
,KStringValue
,LocalDateTimeValue
,LocalDateValue
,LocalTimeValue
,LongValue
,MonthDayValue
,NumberValue
,OffsetDateTimeValue
,OffsetTimeValue
,PeriodValue
,ShortValue
,StringValue
,TermporalAccessorValue
,TermporalAmountValue
,XMLDurationValue
,XMLGregorianCalendarValue
,YearMonthValue
,YearValue
,ZonedDateTimeValue
public interface IValueObject<TYPE>
Interface to create a value object for the data type, or to convert to it.Pattern is defined to be able to select formatters of different types, before passing in the rest of the pattern. If this is the case, the pattern string must begin with [type], where "type" is one of:
- "short" (for date/time)
- "medium" (for date/time)
- "long" (for date/time)
- "full" (for date/time)
- integer (for numeric values)
- currency (for numeric values)
- percent (for numeric values)
In addition, the resolver style for how a value is parsed from a String can be specified in the start of the pattern as:
- [strict],
- [smart], or
- [lenient].
- Author:
- Christopher Mindus
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PATTERN_BASIC_ISO_DATE
The pattern: Basic ISO date '20111203'.static java.lang.String
PATTERN_CURRENCY
The pattern "currency" for numeric values.static java.lang.String
PATTERN_FULL
The pattern "full" for date/time.static java.lang.String
PATTERN_INTEGER
The pattern "integer" for numeric values.static java.lang.String
PATTERN_ISO_DATE
The pattern: ISO Date with or without offset '2011-12-03+01:00'; '2011-12-03'.static java.lang.String
PATTERN_ISO_DATE_TIME
The pattern: Date and time with ZoneId '2011-12-03T10:15:30+01:00[Europe/Paris]'.static java.lang.String
PATTERN_ISO_INSTANT
The pattern: Date and Time of an Instant '2011-12-03T10:15:30Z'.static java.lang.String
PATTERN_ISO_LOCAL_DATE
The pattern: ISO Local Date '2011-12-03'.static java.lang.String
PATTERN_ISO_LOCAL_DATE_TIME
The pattern: ISO Local Date and Time '2011-12-03T10:15:30'.static java.lang.String
PATTERN_ISO_LOCAL_TIME
The pattern: Time without offset '10:15:30'.static java.lang.String
PATTERN_ISO_OFFSET_DATE
The pattern: ISO Date with offset '2011-12-03+01:00'.static java.lang.String
PATTERN_ISO_OFFSET_DATE_TIME
The pattern: Date Time with Offset 2011-12-03T10:15:30+01:00'.static java.lang.String
PATTERN_ISO_OFFSET_TIME
The pattern: Time with offset '10:15:30+01:00'.static java.lang.String
PATTERN_ISO_ORDINAL_DATE
The pattern: Year and day of year '2012-337'.static java.lang.String
PATTERN_ISO_TIME
The pattern: Time with or without offset '10:15:30+01:00'; '10:15:30'.static java.lang.String
PATTERN_ISO_WEEK_DATE
The pattern: Year and Week 2012-W48-6'.static java.lang.String
PATTERN_ISO_ZONED_DATE_TIME
The pattern: Zoned Date Time '2011-12-03T10:15:30+01:00[Europe/Paris]'.static java.lang.String
PATTERN_LONG
The pattern "long" for date/time.static java.lang.String
PATTERN_MEDIUM
The pattern "medium" for date/time.static java.lang.String
PATTERN_PERCENT
The pattern "percent" for numeric values.static java.lang.String
PATTERN_RFC_1123_DATE_TIME
The pattern: RFC 1123 / RFC 822 'Tue, 3 Jun 2008 11:05:30 GMT'.static java.lang.String
PATTERN_SHORT
The pattern "short" for date/time.static java.lang.String
RESOLVER_LENIENT
Resolver style for parsing date/time, should precede the pattern string.static java.lang.String
RESOLVER_LENIENT_NO_BRACKETS
static java.lang.String
RESOLVER_SMART
Resolver style for parsing date/time, should precede the pattern string.static java.lang.String
RESOLVER_SMART_NO_BRACKETS
static java.lang.String
RESOLVER_STRICT
Resolver style for parsing date/time, should precede the pattern string.static java.lang.String
RESOLVER_STRICT_NO_BRACKETS
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description long
asLong(TYPE value, LocaleInfo localeInfo)
Returns a long value if possible.default long
asLongCast(java.lang.Object value, LocaleInfo localeInfo)
Returns a long value if possible.TYPE
convert(java.lang.Object value, Value.Type oldType, LocaleInfo localeInfo)
Converts a value from another type.TYPE
createDefault()
Creates the default value object for the data type.java.lang.String
getDescription()
Gets the description of the type, used for the Designer.java.text.Format
getFormatter(java.lang.String pattern, LocaleInfo localeInfo)
Returns the Formatter for a pattern.java.lang.Class<TYPE>
getValueClass()
Gets the class of the value.Value.Type
getValueType()
Gets the value type.default boolean
isRightAligned()
Checks if this type is right-aligned in table columns.TYPE
load(java.lang.String value, org.w3c.dom.Element element)
Loads the value from an Element.TYPE
parse(java.lang.String value)
Creates a Value object from a String using a specified pattern and locale.TYPE
parse(java.lang.String value, java.lang.String pattern, LocaleInfo localeInfo)
Creates a Value object from a String using a specified pattern and locale.java.lang.String
save(TYPE value, org.w3c.dom.Element element)
Saves the value to an Element.default java.lang.String
saveCast(java.lang.Object value, org.w3c.dom.Element element)
Saves the value to an Element.java.lang.String
toString(TYPE value)
The default "toString" representation.java.lang.String
toString(TYPE value, java.lang.String pattern, LocaleInfo localeInfo)
Formats the value to a String.default java.lang.String
toStringCast(java.lang.Object value, java.lang.String pattern, LocaleInfo localeInfo)
Formats the value to a String.default java.lang.String
toStringForced(java.lang.Object value)
Calls the "toString" method with any object, casting it.
Field Detail
PATTERN_SHORT
static final java.lang.String PATTERN_SHORT
The pattern "short" for date/time.- See Also:
- Constant Field Values
PATTERN_MEDIUM
static final java.lang.String PATTERN_MEDIUM
The pattern "medium" for date/time.- See Also:
- Constant Field Values
PATTERN_LONG
static final java.lang.String PATTERN_LONG
The pattern "long" for date/time.- See Also:
- Constant Field Values
PATTERN_FULL
static final java.lang.String PATTERN_FULL
The pattern "full" for date/time.- See Also:
- Constant Field Values
PATTERN_BASIC_ISO_DATE
static final java.lang.String PATTERN_BASIC_ISO_DATE
The pattern: Basic ISO date '20111203'.- See Also:
- Constant Field Values
PATTERN_ISO_LOCAL_DATE
static final java.lang.String PATTERN_ISO_LOCAL_DATE
The pattern: ISO Local Date '2011-12-03'.- See Also:
- Constant Field Values
PATTERN_ISO_OFFSET_DATE
static final java.lang.String PATTERN_ISO_OFFSET_DATE
The pattern: ISO Date with offset '2011-12-03+01:00'.- See Also:
- Constant Field Values
PATTERN_ISO_DATE
static final java.lang.String PATTERN_ISO_DATE
The pattern: ISO Date with or without offset '2011-12-03+01:00'; '2011-12-03'.- See Also:
- Constant Field Values
PATTERN_ISO_LOCAL_TIME
static final java.lang.String PATTERN_ISO_LOCAL_TIME
The pattern: Time without offset '10:15:30'.- See Also:
- Constant Field Values
PATTERN_ISO_OFFSET_TIME
static final java.lang.String PATTERN_ISO_OFFSET_TIME
The pattern: Time with offset '10:15:30+01:00'.- See Also:
- Constant Field Values
PATTERN_ISO_TIME
static final java.lang.String PATTERN_ISO_TIME
The pattern: Time with or without offset '10:15:30+01:00'; '10:15:30'.- See Also:
- Constant Field Values
PATTERN_ISO_LOCAL_DATE_TIME
static final java.lang.String PATTERN_ISO_LOCAL_DATE_TIME
The pattern: ISO Local Date and Time '2011-12-03T10:15:30'.- See Also:
- Constant Field Values
PATTERN_ISO_OFFSET_DATE_TIME
static final java.lang.String PATTERN_ISO_OFFSET_DATE_TIME
The pattern: Date Time with Offset 2011-12-03T10:15:30+01:00'.- See Also:
- Constant Field Values
PATTERN_ISO_ZONED_DATE_TIME
static final java.lang.String PATTERN_ISO_ZONED_DATE_TIME
The pattern: Zoned Date Time '2011-12-03T10:15:30+01:00[Europe/Paris]'.- See Also:
- Constant Field Values
PATTERN_ISO_DATE_TIME
static final java.lang.String PATTERN_ISO_DATE_TIME
The pattern: Date and time with ZoneId '2011-12-03T10:15:30+01:00[Europe/Paris]'.- See Also:
- Constant Field Values
PATTERN_ISO_ORDINAL_DATE
static final java.lang.String PATTERN_ISO_ORDINAL_DATE
The pattern: Year and day of year '2012-337'.- See Also:
- Constant Field Values
PATTERN_ISO_WEEK_DATE
static final java.lang.String PATTERN_ISO_WEEK_DATE
The pattern: Year and Week 2012-W48-6'.- See Also:
- Constant Field Values
PATTERN_ISO_INSTANT
static final java.lang.String PATTERN_ISO_INSTANT
The pattern: Date and Time of an Instant '2011-12-03T10:15:30Z'.- See Also:
- Constant Field Values
PATTERN_RFC_1123_DATE_TIME
static final java.lang.String PATTERN_RFC_1123_DATE_TIME
The pattern: RFC 1123 / RFC 822 'Tue, 3 Jun 2008 11:05:30 GMT'.- See Also:
- Constant Field Values
PATTERN_INTEGER
static final java.lang.String PATTERN_INTEGER
The pattern "integer" for numeric values.- See Also:
- Constant Field Values
PATTERN_PERCENT
static final java.lang.String PATTERN_PERCENT
The pattern "percent" for numeric values.- See Also:
- Constant Field Values
PATTERN_CURRENCY
static final java.lang.String PATTERN_CURRENCY
The pattern "currency" for numeric values.- See Also:
- Constant Field Values
RESOLVER_STRICT
static final java.lang.String RESOLVER_STRICT
Resolver style for parsing date/time, should precede the pattern string.Style to resolve dates and times strictly.
Using strict resolution will ensure that all parsed values are within the outer range of valid values for the field. Individual fields may be further processed for strictness.
For example, resolving year-month and day-of-month in the ISO calendar system using strict mode will ensure that the day-of-month is valid for the year-month, rejecting invalid values.
- See Also:
- Constant Field Values
RESOLVER_STRICT_NO_BRACKETS
static final java.lang.String RESOLVER_STRICT_NO_BRACKETS
- See Also:
- Constant Field Values
RESOLVER_SMART
static final java.lang.String RESOLVER_SMART
Resolver style for parsing date/time, should precede the pattern string.Style to resolve dates and times in a smart, or intelligent, manner.
Using smart resolution will perform the sensible default for each field, which may be the same as strict, the same as lenient, or a third behavior. Individual fields will interpret this differently.
For example, resolving year-month and day-of-month in the ISO calendar system using smart mode will ensure that the day-of-month is from 1 to 31, converting any value beyond the last valid day-of-month to be the last valid day-of-month.
- See Also:
- Constant Field Values
RESOLVER_SMART_NO_BRACKETS
static final java.lang.String RESOLVER_SMART_NO_BRACKETS
- See Also:
- Constant Field Values
RESOLVER_LENIENT
static final java.lang.String RESOLVER_LENIENT
Resolver style for parsing date/time, should precede the pattern string.Style to resolve dates and times leniently.
Using lenient resolution will resolve the values in an appropriate lenient manner. Individual fields will interpret this differently.
For example, lenient mode allows the month in the ISO calendar system to be outside the range 1 to 12. For example, month 15 is treated as being 3 months after month 12.
- See Also:
- Constant Field Values
RESOLVER_LENIENT_NO_BRACKETS
static final java.lang.String RESOLVER_LENIENT_NO_BRACKETS
- See Also:
- Constant Field Values
Method Detail
getValueType
Value.Type getValueType()
Gets the value type.
getValueClass
java.lang.Class<TYPE> getValueClass()
Gets the class of the value.
getDescription
java.lang.String getDescription()
Gets the description of the type, used for the Designer.
createDefault
TYPE createDefault()
Creates the default value object for the data type.- Returns:
- The default value.
isRightAligned
default boolean isRightAligned()
Checks if this type is right-aligned in table columns.- Returns:
- true for right-aligned values, default is false: left-aligned.
getFormatter
java.text.Format getFormatter(java.lang.String pattern, LocaleInfo localeInfo) throws java.lang.IllegalArgumentException
Returns the Formatter for a pattern.- Parameters:
pattern
- The pattern to use, null for none.localeInfo
- The locale information instance, or null for none.- Returns:
- The formatter to use, or null for none.
- Throws:
java.lang.IllegalArgumentException
- For formatter errors.
toString
java.lang.String toString(TYPE value)
The default "toString" representation.- Parameters:
value
- The value could be null.- Returns:
- The String representation.
toStringForced
default java.lang.String toStringForced(java.lang.Object value)
Calls the "toString" method with any object, casting it. IF casting fails, which should not be, thenString.valueOf(value)
is called.- Parameters:
value
- The value could be null.- Returns:
- The String representation.
toString
java.lang.String toString(TYPE value, java.lang.String pattern, LocaleInfo localeInfo) throws java.lang.IllegalArgumentException, java.lang.Exception
Formats the value to a String.- Parameters:
value
- The value is never null.pattern
- Pattern to use, null for none.localeInfo
- The locale information instance, or null for none.- Returns:
- The String representation using specified pattern and locale information.
- Throws:
java.lang.IllegalArgumentException
- For formatter errors.java.lang.Exception
- For other errors.
toStringCast
default java.lang.String toStringCast(java.lang.Object value, java.lang.String pattern, LocaleInfo localeInfo) throws java.lang.IllegalArgumentException, java.lang.Exception
Formats the value to a String.- Parameters:
value
- The value is never null.pattern
- Pattern to use, null for none.localeInfo
- The locale information instance, or null for none.- Returns:
- The String representation using specified pattern and locale information.
- Throws:
java.lang.IllegalArgumentException
- For formatter errors.java.lang.Exception
- For other errors.
parse
TYPE parse(java.lang.String value) throws java.text.ParseException, java.lang.IllegalArgumentException, java.lang.Exception
Creates a Value object from a String using a specified pattern and locale.- Parameters:
value
- The value, never null.- Returns:
- The value object, never null.
- Throws:
java.text.ParseException
- If the value could not be parsed.java.lang.IllegalArgumentException
- For pattern errors.java.lang.Exception
- For other errors.
parse
TYPE parse(java.lang.String value, java.lang.String pattern, LocaleInfo localeInfo) throws java.text.ParseException, java.lang.IllegalArgumentException, java.lang.Exception
Creates a Value object from a String using a specified pattern and locale.- Parameters:
value
- The value, never null.pattern
- The pattern, null for none.localeInfo
- The locale info, null for default.- Returns:
- The value object, never null.
- Throws:
java.text.ParseException
- If the value could not be parsed.java.lang.IllegalArgumentException
- For pattern errors.java.lang.Exception
- For other errors.
load
TYPE load(java.lang.String value, org.w3c.dom.Element element) throws java.lang.Exception
Loads the value from an Element.- Parameters:
value
- The String value in the element.element
- The element holding the information for advanced processing using JAXB.- Throws:
java.lang.Exception
- An exception due to parsing, bean unmarshalling, etc.
save
java.lang.String save(TYPE value, org.w3c.dom.Element element) throws java.lang.Exception
Saves the value to an Element.- Parameters:
value
- The value to save.element
- The element to save information into for advanced processing using JAXB.- Returns:
- The String value to set in the Element, or null if advanced processing is used.
- Throws:
java.lang.Exception
saveCast
default java.lang.String saveCast(java.lang.Object value, org.w3c.dom.Element element) throws java.lang.Exception
Saves the value to an Element.- Parameters:
value
- The value to save.element
- The element to save information into for advanced processing using JAXB.- Returns:
- The String value to set in the Element, or null if advanced processing is used.
- Throws:
java.lang.Exception
convert
TYPE convert(java.lang.Object value, Value.Type oldType, LocaleInfo localeInfo) throws java.lang.Exception
Converts a value from another type. If the type is not defined, check the object instance for possible conversions.- Parameters:
value
- The value to convert.oldType
- The old type, null for not defined or unknown.localeInfo
- The locale information, null to look-up from current thread or if not found, for system default.- Returns:
- The value object.
- Throws:
java.lang.Exception
- For other errors.java.text.ParseException
- If this conversion fails.
asLong
long asLong(TYPE value, LocaleInfo localeInfo)
Returns a long value if possible.- Parameters:
value
- The Value object.localeInfo
- The locale information, null to look-up from current thread or if not found, for system default.- Returns:
- The long value, e.g. in milliseconds, or Long.MIN_VALUE for not possible.
asLongCast
default long asLongCast(java.lang.Object value, LocaleInfo localeInfo)
Returns a long value if possible.- Parameters:
value
- The Value object.localeInfo
- The locale information, null to look-up from current thread or if not found, for system default.- Returns:
- The long value, e.g. in milliseconds, or Long.MIN_VALUE for not possible.