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 isequal
to the givenvalue
.boolean
Fundamentally, check thatvalue
satisfies this constraint and throw an exception otherwise.protected boolean
validateRange
(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: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 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: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 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
value
is valid. - Throws:
QuantityConversionException
- if the constraint isn't satisfied in some other way
-
validateRange
- Throws:
QuantityConversionException
-
persistableString
Description copied from interface:IConstraint
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 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: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 extends Comparable<T>>
- Returns:
- a valid value for this instance
- Throws:
QuantityConversionException
- ifpersistedValue
couldn't be parsed or didn't satisfy the constraint
-
interactiveFormat
Description copied from interface:IConstraint
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 extends Comparable<T>>
- Returns:
- a string representation taking locale and internationalization into account.
- Throws:
QuantityConversionException
- ifvalue
doesn't satisfy the constraint
-
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 extends Comparable<T>>
- Returns:
- a valid value for this instance
- Throws:
QuantityConversionException
- ifinteractiveValue
couldn't be parsed or didn't satisfy the constraint
-
format
- Specified by:
format
in interfaceIFormatter<T extends Comparable<T>>
-