T
- the type of values that the constraint operates onpublic interface IConstraint<T>
T
, including constrained
conversions to and from persistable and interactive strings.Modifier and Type | Method and Description |
---|---|
IConstraint<T> |
combine(IConstraint<?> other)
Return a constraint that honors both this constraint and
other , if such a constraint
would accept anything except null . |
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
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. |
IConstraint<T> combine(IConstraint<?> other)
other
, if such a constraint
would accept anything except null
. Otherwise, return null
.null
boolean validate(T value) throws QuantityConversionException
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.value
is valid.NullPointerException
- if value
is null and this constraint doesn't allow itIllegalArgumentException
- if some type aspect of value
prevents it from being validQuantityConversionException
- if the constraint isn't satisfied in some other wayString persistableString(T value) throws QuantityConversionException
parsePersisted(String)
(on this instance) yields a result that is
equal
to the given value
. That is, the exact
representation must be preserved.NullPointerException
- if value
is null and this constraint doesn't allow itIllegalArgumentException
- if some type aspect of value
prevents it from being validQuantityConversionException
- if the constraint isn't satisfied in some other wayT parsePersisted(String persistedValue) throws QuantityConversionException
persistableString(Object)
on this instance. Only use this on persisted strings,
never for interactive input.NullPointerException
- if persistedValue
is nullQuantityConversionException
- if persistedValue
couldn't be parsed or didn't satisfy the constraintString interactiveFormat(T value) throws QuantityConversionException
parseInteractive(String)
(on this instance) yields a result that is
equal
to the given value
. That is, the exact
representation must be preserved.NullPointerException
- if value
is null and this constraint doesn't allow itIllegalArgumentException
- if some type aspect of value
prevents it from being validQuantityConversionException
- if value
doesn't satisfy the constraintT parseInteractive(String interactiveValue) throws QuantityConversionException
interactiveFormat(Object)
on this instance and in the same locale. Only use this for
interactive input, never for persisted strings.NullPointerException
- if interactiveValue
is nullQuantityConversionException
- if interactiveValue
couldn't be parsed or didn't satisfy the constraintCopyright © 2020. All rights reserved.