Package org.openjdk.jmc.common.unit
Class WrappingPersister<T>
java.lang.Object
org.openjdk.jmc.common.unit.WrappingPersister<T>
- All Implemented Interfaces:
IConstraint<T>
,IPersister<T>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncombine
(IConstraint<?> other) Return a constraint that honors both this constraint andother
, if such a constraint would accept anything exceptnull
.interactiveFormat
(T value) An exact string representation taking locale and internationalization into account.parseInteractive
(String interactiveValue) Parse an interactive string.parsePersisted
(String persistedValue) Parse a persisted string.persistableString
(T value) A string representation independent of locale or internationalization, that when parsed usingIConstraint.parsePersisted(String)
(on this instance) yields a result that isequal
to the givenvalue
.boolean
Fundamentally, check thatvalue
satisfies this constraint and throw an exception otherwise.
-
Constructor Details
-
WrappingPersister
-
-
Method Details
-
persistableString
Description copied from interface:IPersister
A string representation independent of locale or internationalization, that when parsed usingIConstraint.parsePersisted(String)
(on this instance) yields a result that isequal
to the givenvalue
. That is, the exact representation must be preserved.- Specified by:
persistableString
in interfaceIConstraint<T>
- Specified by:
persistableString
in interfaceIPersister<T>
- Returns:
- a string representation independent of locale or internationalization.
-
parsePersisted
Description copied from interface:IConstraint
Parse a persisted string. Only guaranteed to be able to parse strings produced byIConstraint.persistableString(Object)
on this instance. Only use this on persisted strings, never for interactive input.- Specified by:
parsePersisted
in interfaceIConstraint<T>
- Returns:
- a valid value for this instance
- Throws:
QuantityConversionException
- ifpersistedValue
couldn't be parsed or didn't satisfy the constraint
-
combine
Description copied from interface:IConstraint
Return a constraint that honors both this constraint andother
, if such a constraint would accept anything exceptnull
. Otherwise, returnnull
.- Specified by:
combine
in interfaceIConstraint<T>
- Returns:
- a constraint or
null
-
parseInteractive
Description copied from interface:IConstraint
Parse an interactive string. Only guaranteed to be able to parse strings produced byIConstraint.interactiveFormat(Object)
on this instance and in the same locale. Only use this for interactive input, never for persisted strings.- Specified by:
parseInteractive
in interfaceIConstraint<T>
- Returns:
- a valid value for this instance
- Throws:
QuantityConversionException
- ifinteractiveValue
couldn't be parsed or didn't satisfy the constraint
-
validate
Description copied from interface:IConstraint
Fundamentally, check thatvalue
satisfies this constraint and throw an exception otherwise. As long as the method returns normally,value
is a valid value, regardless of the return value. However, when wrapping a persister in a constraint, it is possible that the persister treats some magic values differently. If the constraint isn't aware of these magical values it should typically not try to validate them. This is signaled by the persister by returning true from this method.- Specified by:
validate
in interfaceIConstraint<T>
- Specified by:
validate
in interfaceIPersister<T>
- Returns:
- true if this value is considered magical and further validation should be skipped,
false otherwise. Any return value mean that the
value
is valid.
-
interactiveFormat
Description copied from interface:IPersister
An exact string representation taking locale and internationalization into account. When parsed usingIConstraint.parseInteractive(String)
(on this instance) yields a result that isequal
to the givenvalue
. That is, the exact representation must be preserved.- Specified by:
interactiveFormat
in interfaceIConstraint<T>
- Specified by:
interactiveFormat
in interfaceIPersister<T>
- Returns:
- a string representation taking locale and internationalization into account.
-