T
- the type of values that the constraint operates onpublic final class ComparableConstraint<T extends Comparable<T>> extends Object implements IConstraint<T>, IFormatter<T>
constraint
that wraps a persister
for Comparable
values, and constrains the allowed values with minimum and maximum values.Constructor and Description |
---|
ComparableConstraint(IPersister<T> persister,
T min,
T max) |
Modifier and Type | Method and Description |
---|---|
ComparableConstraint<T> |
combine(IConstraint<?> other)
Return a constraint that honors both this constraint and
other , if such a constraint
would accept anything except null . |
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>> |
constrain(IConstraint<U> constraint,
String persistedMin,
String persistedMax) |
static <U,T extends Comparable<T>> |
constrain(IConstraint<U> constraint,
U min,
U max) |
String |
format(T value) |
String |
interactiveFormat(T value)
An exact string representation taking locale and internationalization into account.
|
T |
parseInteractive(String interactiveValue)
Parse an interactive string.
|
T |
parsePersisted(String persistedValue)
Parse a persisted string.
|
String |
persistableString(T value)
A string representation independent of locale or internationalization, that when parsed using
IConstraint.parsePersisted(String) (on this instance) yields a result that is
equal to the given value . |
boolean |
validate(T value)
Fundamentally, check that
value satisfies this constraint and throw an exception
otherwise. |
protected boolean |
validateRange(T value) |
public ComparableConstraint(IPersister<T> persister, T min, T max)
public static <U,T extends Comparable<T>> IConstraint<U> constrain(IConstraint<U> constraint, String persistedMin, String persistedMax) throws QuantityConversionException
QuantityConversionException
public static <U,T extends Comparable<T>> IConstraint<U> constrain(IConstraint<U> constraint, U min, U max)
public ComparableConstraint<T> combine(IConstraint<?> other)
IConstraint
other
, if such a constraint
would accept anything except null
. Otherwise, return null
.combine
in interface IConstraint<T extends Comparable<T>>
null
protected ComparableConstraint<T> combineNonSame(ComparableConstraint<T> other)
null
public boolean validate(T value) throws QuantityConversionException
IConstraint
value
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.validate
in interface IConstraint<T extends Comparable<T>>
value
is valid.QuantityConversionException
- if the constraint isn't satisfied in some other wayprotected boolean validateRange(T value) throws QuantityConversionException
QuantityConversionException
public String persistableString(T value) throws QuantityConversionException
IConstraint
IConstraint.parsePersisted(String)
(on this instance) yields a result that is
equal
to the given value
. That is, the exact
representation must be preserved.persistableString
in interface IConstraint<T extends Comparable<T>>
QuantityConversionException
- if the constraint isn't satisfied in some other waypublic T parsePersisted(String persistedValue) throws QuantityConversionException
IConstraint
IConstraint.persistableString(Object)
on this instance. Only use this on persisted strings,
never for interactive input.parsePersisted
in interface IConstraint<T extends Comparable<T>>
QuantityConversionException
- if persistedValue
couldn't be parsed or didn't satisfy the constraintpublic String interactiveFormat(T value) throws QuantityConversionException
IConstraint
IConstraint.parseInteractive(String)
(on this instance) yields a result that is
equal
to the given value
. That is, the exact
representation must be preserved.interactiveFormat
in interface IConstraint<T extends Comparable<T>>
QuantityConversionException
- if value
doesn't satisfy the constraintpublic T parseInteractive(String interactiveValue) throws QuantityConversionException
IConstraint
IConstraint.interactiveFormat(Object)
on this instance and in the same locale. Only use this for
interactive input, never for persisted strings.parseInteractive
in interface IConstraint<T extends Comparable<T>>
QuantityConversionException
- if interactiveValue
couldn't be parsed or didn't satisfy the constraintpublic String format(T value)
format
in interface IFormatter<T extends Comparable<T>>
Copyright © 2020. All rights reserved.