Package org.openjdk.jmc.common.unit
Interface IConstraint<T>
- 
- Type Parameters:
- T- the type of values that the constraint operates on
 - All Known Subinterfaces:
- IPersister<T>
 - All Known Implementing Classes:
- ComparableConstraint,- KindOfQuantity,- LinearKindOfQuantity,- WrappingPersister
 
 public interface IConstraint<T>A constraint on allowed instances of an existing typeT, including constrained conversions to and from persistable and interactive strings.
- 
- 
Method SummaryAll Methods Instance Methods Abstract 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 usingparsePersisted(String)(on this instance) yields a result that isequalto the givenvalue.booleanvalidate(T value)Fundamentally, check thatvaluesatisfies this constraint and throw an exception otherwise.
 
- 
- 
- 
Method Detail- 
combineIConstraint<T> combine(IConstraint<?> other) Return a constraint that honors both this constraint andother, if such a constraint would accept anything exceptnull. Otherwise, returnnull.- Returns:
- a constraint or null
 
 - 
validateboolean validate(T value) throws QuantityConversionException Fundamentally, 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.- Returns:
- true if this value is considered magical and further validation should be skipped,
         false otherwise. Any return value mean that the valueis valid.
- Throws:
- NullPointerException- if- valueis null and this constraint doesn't allow it
- IllegalArgumentException- if some type aspect of- valueprevents it from being valid
- QuantityConversionException- if the constraint isn't satisfied in some other way
 
 - 
persistableStringString persistableString(T value) throws QuantityConversionException A string representation independent of locale or internationalization, that when parsed usingparsePersisted(String)(on this instance) yields a result that isequalto the givenvalue. That is, the exact representation must be preserved.- Returns:
- a string representation independent of locale or internationalization.
- Throws:
- NullPointerException- if- valueis null and this constraint doesn't allow it
- IllegalArgumentException- if some type aspect of- valueprevents it from being valid
- QuantityConversionException- if the constraint isn't satisfied in some other way
 
 - 
parsePersistedT parsePersisted(String persistedValue) throws QuantityConversionException Parse a persisted string. Only guaranteed to be able to parse strings produced bypersistableString(Object)on this instance. Only use this on persisted strings, never for interactive input.- Returns:
- a valid value for this instance
- Throws:
- NullPointerException- if- persistedValueis null
- QuantityConversionException- if- persistedValuecouldn't be parsed or didn't satisfy the constraint
 
 - 
interactiveFormatString interactiveFormat(T value) throws QuantityConversionException An exact string representation taking locale and internationalization into account. When parsed usingparseInteractive(String)(on this instance) yields a result that isequalto the givenvalue. That is, the exact representation must be preserved.- Returns:
- a string representation taking locale and internationalization into account.
- Throws:
- NullPointerException- if- valueis null and this constraint doesn't allow it
- IllegalArgumentException- if some type aspect of- valueprevents it from being valid
- QuantityConversionException- if- valuedoesn't satisfy the constraint
 
 - 
parseInteractiveT parseInteractive(String interactiveValue) throws QuantityConversionException Parse an interactive string. Only guaranteed to be able to parse strings produced byinteractiveFormat(Object)on this instance and in the same locale. Only use this for interactive input, never for persisted strings.- Returns:
- a valid value for this instance
- Throws:
- NullPointerException- if- interactiveValueis null
- QuantityConversionException- if- interactiveValuecouldn't be parsed or didn't satisfy the constraint
 
 
- 
 
-