Package org.openjdk.jmc.common.unit
Class QuantityConversionException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- org.openjdk.jmc.common.unit.QuantityConversionException
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
QuantityConversionException.Persisted
,QuantityConversionException.Quantity
public abstract class QuantityConversionException extends Exception
Exception denoting problem converting between representations of physical quantities ("numbers with units"). Has a problem enum designating the kind of problem and is able to return a prototype value that could be used to circumvent that problem. Has different representations for persisting/logging (locale independent) and presenting to a human (using the default locale). Be sure to usegetLocalizedMessage()
for error dialogs.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
QuantityConversionException.Persisted
static class
QuantityConversionException.Problem
static class
QuantityConversionException.Quantity
-
Field Summary
Fields Modifier and Type Field Description protected String
badString
protected QuantityConversionException.Problem
problem
-
Constructor Summary
Constructors Modifier Constructor Description protected
QuantityConversionException(QuantityConversionException.Problem problem, String badString)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <Q extends IQuantity>
QuantityConversionExceptionbelowPrecision(Q badValue, Q precisionLimit)
static <T extends Comparable<T>>
QuantityConversionExceptionbelowPrecision(T badValue, T precisionLimit, IPersister<T> persister)
static QuantityConversionException
conflictingConstraints(Object value, String key)
String
getBadString()
The string where the problem was encountered, so that it might be highlighted.abstract String
getInteractivePrototype()
Prototype value suitable to be presented to a human.String
getLocalizedMessage()
String
getMessage()
abstract String
getPersistablePrototype()
Prototype value suitable to be persisted or logged.QuantityConversionException.Problem
getProblem()
The kind of problem encountered.static QuantityConversionException
noUnit(String badString, IQuantity prototype)
static <T extends Comparable<T>>
QuantityConversionExceptionnoUnit(String badString, T prototype, IPersister<T> persister)
static <Q extends IQuantity>
QuantityConversionExceptiontooHigh(Q badValue, Q max)
static <T extends Comparable<T>>
QuantityConversionExceptiontooHigh(T badValue, T max, IPersister<T> persister)
static <Q extends IQuantity>
QuantityConversionExceptiontooLow(Q badValue, Q min)
static <T extends Comparable<T>>
QuantityConversionExceptiontooLow(T badValue, T min, IPersister<T> persister)
String
toString()
static QuantityConversionException
unknownUnit(String badString, IQuantity prototype)
static <T extends Comparable<T>>
QuantityConversionExceptionunknownUnit(String badString, T prototype, IPersister<T> persister)
static QuantityConversionException
unparsable(String badString, IQuantity prototype)
static <T extends Comparable<T>>
QuantityConversionExceptionunparsable(String badString, T prototype, IPersister<T> persister)
-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
-
-
-
Field Detail
-
problem
protected final QuantityConversionException.Problem problem
-
badString
protected final String badString
-
-
Constructor Detail
-
QuantityConversionException
protected QuantityConversionException(QuantityConversionException.Problem problem, String badString)
-
-
Method Detail
-
unparsable
public static <T extends Comparable<T>> QuantityConversionException unparsable(String badString, T prototype, IPersister<T> persister)
-
noUnit
public static <T extends Comparable<T>> QuantityConversionException noUnit(String badString, T prototype, IPersister<T> persister)
-
unknownUnit
public static <T extends Comparable<T>> QuantityConversionException unknownUnit(String badString, T prototype, IPersister<T> persister)
-
tooLow
public static <T extends Comparable<T>> QuantityConversionException tooLow(T badValue, T min, IPersister<T> persister)
-
tooHigh
public static <T extends Comparable<T>> QuantityConversionException tooHigh(T badValue, T max, IPersister<T> persister)
-
belowPrecision
public static <T extends Comparable<T>> QuantityConversionException belowPrecision(T badValue, T precisionLimit, IPersister<T> persister)
-
unparsable
public static QuantityConversionException unparsable(String badString, IQuantity prototype)
-
noUnit
public static QuantityConversionException noUnit(String badString, IQuantity prototype)
-
unknownUnit
public static QuantityConversionException unknownUnit(String badString, IQuantity prototype)
-
tooLow
public static <Q extends IQuantity> QuantityConversionException tooLow(Q badValue, Q min)
-
tooHigh
public static <Q extends IQuantity> QuantityConversionException tooHigh(Q badValue, Q max)
-
belowPrecision
public static <Q extends IQuantity> QuantityConversionException belowPrecision(Q badValue, Q precisionLimit)
-
conflictingConstraints
public static QuantityConversionException conflictingConstraints(Object value, String key)
-
getProblem
public QuantityConversionException.Problem getProblem()
The kind of problem encountered.- Returns:
- one of the
QuantityConversionException.Problem
values, never null
-
getBadString
public String getBadString()
The string where the problem was encountered, so that it might be highlighted. May be the entire string on which parsing was attempted. May be null if this problem was detected after parsing, such as out of range.- Returns:
- a substring of the parser input, or null
-
getPersistablePrototype
public abstract String getPersistablePrototype()
Prototype value suitable to be persisted or logged.- Returns:
- a non-localized (English) value that will prevent this particular problem when parsed.
-
getInteractivePrototype
public abstract String getInteractivePrototype()
Prototype value suitable to be presented to a human. Must not be persisted or logged.- Returns:
- a localized value that will prevent this particular problem when parsed using interactive parsing.
-
getMessage
public String getMessage()
- Overrides:
getMessage
in classThrowable
-
getLocalizedMessage
public String getLocalizedMessage()
- Overrides:
getLocalizedMessage
in classThrowable
-
-