Package org.openjdk.jmc.common.unit
Class ComparableConstraint<T extends Comparable<T>>
java.lang.Object
org.openjdk.jmc.common.unit.ComparableConstraint<T>
- Type Parameters:
T- the type of values that the constraint operates on
- All Implemented Interfaces:
IConstraint<T>,IFormatter<T>
public final class ComparableConstraint<T extends Comparable<T>>
extends Object
implements IConstraint<T>, IFormatter<T>
A
constraint that wraps a persister for Comparable
values, and constrains the allowed values with minimum and maximum values.-
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.protected ComparableConstraint<T>combineNonSame(ComparableConstraint<T> other) Combine with other ComparableConstraint known not to be the same instance, but having the same persister.static <U,T extends Comparable<T>>
IConstraint<U>constrain(IConstraint<U> constraint, String persistedMin, String persistedMax) static <U,T extends Comparable<T>>
IConstraint<U>constrain(IConstraint<U> constraint, U min, U max) 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 isequalto the givenvalue.booleanFundamentally, check thatvaluesatisfies this constraint and throw an exception otherwise.protected booleanvalidateRange(T value)
-
Constructor Details
-
ComparableConstraint
-
-
Method Details
-
constrain
public static <U,T extends Comparable<T>> IConstraint<U> constrain(IConstraint<U> constraint, String persistedMin, String persistedMax) throws QuantityConversionException - Throws:
QuantityConversionException
-
constrain
public static <U,T extends Comparable<T>> IConstraint<U> constrain(IConstraint<U> constraint, U min, U max) -
combine
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 extends Comparable<T>>- Returns:
- a constraint or
null
-
combineNonSame
Combine with other ComparableConstraint known not to be the same instance, but having the same persister.- Returns:
- a combined constraint, if possible, otherwise
null
-
validate
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 extends Comparable<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. - Throws:
QuantityConversionException- if the constraint isn't satisfied in some other way
-
validateRange
- Throws:
QuantityConversionException
-
persistableString
Description copied from interface:IConstraintA 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 extends Comparable<T>>- Returns:
- a string representation independent of locale or internationalization.
- Throws:
QuantityConversionException- if the constraint isn't satisfied in some other way
-
parsePersisted
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 extends Comparable<T>>- Returns:
- a valid value for this instance
- Throws:
QuantityConversionException- ifpersistedValuecouldn't be parsed or didn't satisfy the constraint
-
interactiveFormat
Description copied from interface:IConstraintAn 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 extends Comparable<T>>- Returns:
- a string representation taking locale and internationalization into account.
- Throws:
QuantityConversionException- ifvaluedoesn't satisfy the constraint
-
parseInteractive
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 extends Comparable<T>>- Returns:
- a valid value for this instance
- Throws:
QuantityConversionException- ifinteractiveValuecouldn't be parsed or didn't satisfy the constraint
-
format
- Specified by:
formatin interfaceIFormatter<T extends Comparable<T>>
-