public enum StandardValueRange extends Enum<StandardValueRange> implements ValueRange
StandardNumberType.| Enum Constant and Description |
|---|
BIG_DECIMAL
Big decimal: supports decimals and has a theoretically infinite range of supported values.
|
BIG_INTEGER
Big integer: integer with a theoretically infinite range of supported values.
|
BYTE
Byte: [-128, 127].
|
DOUBLE
Double: [-1.7976931348623157E308, 1.7976931348623157E308].
|
FLOAT
Float: [-3.4028235E38, 3.4028235E38].
|
INTEGER
Integer: [-2147483648, 2147483647].
|
LONG
Long: [-9223372036854775808, 9223372036854775807].
|
SHORT
Short: [-32768, 32767].
|
| Modifier and Type | Method and Description |
|---|---|
static StandardValueRange |
findRangeOrThrow(Number number)
Returns the value range for the type of the given number.
|
@Nullable Number |
getMaxInOwnType() |
@Nullable BigDecimal |
getMaxValue() |
@Nullable Number |
getMinInOwnType() |
@Nullable BigDecimal |
getMinValue() |
boolean |
hasInfinityAndNaN()
Returns whether the type has values for
NaN and infinity, such as Double
with Double.POSITIVE_INFINITY. |
boolean |
supportsAllValuesOf(StandardValueRange other)
Returns whether this range supports all values of the given range.
|
boolean |
supportsDecimals() |
String |
toString() |
static StandardValueRange |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static StandardValueRange[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, valueOfisEqualOrSupersetOf, supportsAllValuesOfpublic static final StandardValueRange BYTE
public static final StandardValueRange SHORT
public static final StandardValueRange INTEGER
public static final StandardValueRange LONG
public static final StandardValueRange FLOAT
public static final StandardValueRange DOUBLE
public static final StandardValueRange BIG_INTEGER
public static final StandardValueRange BIG_DECIMAL
public static StandardValueRange[] values()
for (StandardValueRange c : StandardValueRange.values()) System.out.println(c);
public static StandardValueRange valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic static StandardValueRange findRangeOrThrow(Number number)
IllegalArgumentException is thrown.
The returned range should not be used to derive the given number's class, as multiple types can map to the same value range. For example:
StandardValueRange range1 = detectRangeOrThrow(1L); // Result: LONG
StandardValueRange range2 = detectRangeOrThrow(new AtomicLong(2)); // Result: LONG
StandardValueRange range3 = detectRangeOrThrow(new LongAdder()); // Result: LONG
BigDecimal bigDecimalExtension = new BigDecimal("4") { }; // anonymous extension
StandardValueRange range4 = detectRangeOrThrow(bigDecimalExtension); // Result: BIG_DECIMAL
Use StandardNumberType.fromNumberClass(java.lang.Class<T>) if you want to match the number strictly by its type.
number - the number to determine the value range forpublic boolean supportsDecimals()
supportsDecimals in interface ValueRangepublic boolean hasInfinityAndNaN()
ValueRangeNaN and infinity, such as Double
with Double.POSITIVE_INFINITY.hasInfinityAndNaN in interface ValueRangepublic boolean supportsAllValuesOf(StandardValueRange other)
ValueRange.supportsAllValuesOf(ch.jalu.typeresolver.numbers.ValueRange<?>) for
details. This method exists as a convenience to avoid unchecked warnings when comparing two
StandardValueRange objects.other - the range to check withpublic String toString()
toString in class Enum<StandardValueRange>@Nullable public @Nullable BigDecimal getMinValue()
getMinValue in interface ValueRange@Nullable public @Nullable BigDecimal getMaxValue()
getMaxValue in interface ValueRange@Nullable public @Nullable Number getMinInOwnType()
getMinInOwnType in interface ValueRange@Nullable public @Nullable Number getMaxInOwnType()
getMaxInOwnType in interface ValueRangeCopyright © 2023. All rights reserved.