};
private static final Map<Class<? extends Number>, Function<Number, Number>> CONVERTERS;
+
static {
final ImmutableMap.Builder<Class<? extends Number>, Function<Number, Number>> b = ImmutableMap.builder();
b.put(Byte.class, input -> {
return Byte.valueOf(input.toString());
});
b.put(Short.class, input -> {
- if (input instanceof Short) {
- return input;
- }
- if (input instanceof Byte) {
- return input.shortValue();
- }
+ if (input instanceof Short) {
+ return input;
+ }
+ if (input instanceof Byte) {
+ return input.shortValue();
+ }
- return Short.valueOf(input.toString());
+ return Short.valueOf(input.toString());
});
b.put(Integer.class, input -> {
if (input instanceof Integer) {
if (input instanceof BigDecimal) {
return input;
}
- if (input instanceof Byte || input instanceof Short ||
- input instanceof Integer || input instanceof Long) {
+ if (input instanceof Byte || input instanceof Short || input instanceof Integer || input instanceof Long) {
return BigDecimal.valueOf(input.longValue());
}
if (input instanceof BigInteger) {
return input;
}
- if (input instanceof Byte || input instanceof Short ||
- input instanceof Integer || input instanceof Long) {
+ if (input instanceof Byte || input instanceof Short || input instanceof Integer || input instanceof Long) {
return BigInteger.valueOf(input.longValue());
}
}
static boolean isRangeCovered(final Number min, final Number max, final Number superMin, final Number superMax) {
- return NumberUtil.NUMBER_COMPARATOR.compare(min, superMin) >= 0 &&
- NumberUtil.NUMBER_COMPARATOR.compare(max, superMax) <= 0;
+ return NumberUtil.NUMBER_COMPARATOR.compare(min, superMin) >= 0
+ && NumberUtil.NUMBER_COMPARATOR.compare(max, superMax) <= 0;
}
}