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>
public abstract class WrappingPersister<T> extends Object implements IPersister<T>
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedWrappingPersister(IPersister<T> delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IConstraint<T>combine(IConstraint<?> other)Return a constraint that honors both this constraint andother, if such a constraint would accept anything exceptnull.StringinteractiveFormat(T value)An exact string representation taking locale and internationalization into account.TparseInteractive(String interactiveValue)Parse an interactive string.TparsePersisted(String persistedValue)Parse a persisted string.StringpersistableString(T value)A string representation independent of locale or internationalization, that when parsed usingIConstraint.parsePersisted(String)(on this instance) yields a result that isequalto the givenvalue.booleanvalidate(T value)Fundamentally, check thatvaluesatisfies this constraint and throw an exception otherwise.
-
-
-
Constructor Detail
-
WrappingPersister
protected WrappingPersister(IPersister<T> delegate)
-
-
Method Detail
-
persistableString
public String persistableString(T value)
Description copied from interface:IPersisterA string representation independent of locale or internationalization, that when parsed usingIConstraint.parsePersisted(String)(on this instance) yields a result that isequalto the givenvalue. That is, the exact representation must be preserved.- Specified by:
persistableStringin interfaceIConstraint<T>- Specified by:
persistableStringin interfaceIPersister<T>- Returns:
- a string representation independent of locale or internationalization.
-
parsePersisted
public T parsePersisted(String persistedValue) throws QuantityConversionException
Description copied from interface:IConstraintParse 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:
parsePersistedin interfaceIConstraint<T>- Returns:
- a valid value for this instance
- Throws:
QuantityConversionException- ifpersistedValuecouldn't be parsed or didn't satisfy the constraint
-
combine
public IConstraint<T> combine(IConstraint<?> other)
Description copied from interface:IConstraintReturn a constraint that honors both this constraint andother, if such a constraint would accept anything exceptnull. Otherwise, returnnull.- Specified by:
combinein interfaceIConstraint<T>- Returns:
- a constraint or
null
-
parseInteractive
public T parseInteractive(String interactiveValue) throws QuantityConversionException
Description copied from interface:IConstraintParse 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:
parseInteractivein interfaceIConstraint<T>- Returns:
- a valid value for this instance
- Throws:
QuantityConversionException- ifinteractiveValuecouldn't be parsed or didn't satisfy the constraint
-
validate
public boolean validate(T value)
Description copied from interface:IConstraintFundamentally, check thatvaluesatisfies this constraint and throw an exception otherwise. As long as the method returns normally,valueis 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:
validatein interfaceIConstraint<T>- Specified by:
validatein interfaceIPersister<T>- Returns:
- true if this value is considered magical and further validation should be skipped,
false otherwise. Any return value mean that the
valueis valid.
-
interactiveFormat
public String interactiveFormat(T value)
Description copied from interface:IPersisterAn exact string representation taking locale and internationalization into account. When parsed usingIConstraint.parseInteractive(String)(on this instance) yields a result that isequalto the givenvalue. That is, the exact representation must be preserved.- Specified by:
interactiveFormatin interfaceIConstraint<T>- Specified by:
interactiveFormatin interfaceIPersister<T>- Returns:
- a string representation taking locale and internationalization into account.
-
-