NumberTypeImpl implements NumberType<NUMBER> { @Override public int getExactnessDifference(NumberType<?> otherType) { return this.exactness - ((NumberTypeImpl<?>) otherType).exactness; } NumberTypeImpl(int exactness, NUMBER min, NUMBER max); @Override @SuppressWarnings("unchecked") NUMBER valueOf(Number number, boolean failIfUnprecise); @Override NUMBER valueOf(String number); @Override int getExactnessDifference(NumberType<?> otherType); @Override NUMBER getMinimumValue(); @Override NUMBER getMaximumValue(); static final NumberTypeImpl<Byte> BYTE; static final NumberTypeImpl<Short> SHORT; static final NumberTypeImpl<Integer> INTEGER; static final NumberTypeImpl<Long> LONG; static final NumberTypeImpl<Float> FLOAT; static final NumberTypeImpl<Double> DOUBLE; static final NumberTypeImpl<BigInteger> BIG_INTEGER; static final NumberTypeImpl<BigDecimal> BIG_DECIMAL; }
@Test public void testExcactnesDifference() { NumberType[] numberTypeOrder = new NumberType[] { NumberTypeImpl.BYTE, NumberTypeImpl.SHORT, NumberTypeImpl.INTEGER, NumberTypeImpl.LONG, NumberTypeImpl.BIG_INTEGER }; for (int i = 1; i < numberTypeOrder.length; i++) { NumberType lessExact = numberTypeOrder[i - i]; NumberType moreExact = numberTypeOrder[i]; int diff = moreExact.getExactnessDifference(lessExact); assertTrue(diff > 0); int inverseDiff = lessExact.getExactnessDifference(moreExact); assertEquals(diff, -inverseDiff); } int diff = MathUtilImpl.ATOMIC_INTEGER.getExactnessDifference(NumberTypeImpl.INTEGER); assertEquals(0, diff); diff = MathUtilImpl.ATOMIC_LONG.getExactnessDifference(NumberTypeImpl.LONG); assertEquals(0, diff); }