SafeNumberOperationUtils { public static boolean safeEquals(final Collection<Comparable<?>> sourceCollection, final Collection<Comparable<?>> targetCollection) { List<Comparable<?>> collection = Lists.newArrayList(sourceCollection); collection.addAll(targetCollection); Class<?> clazz = getTargetNumericType(collection); if (null == clazz) { return sourceCollection.equals(targetCollection); } List<Comparable<?>> sourceClazzCollection = sourceCollection.stream().map(number -> parseNumberByClazz(number.toString(), clazz)).collect(Collectors.toList()); List<Comparable<?>> targetClazzCollection = targetCollection.stream().map(number -> parseNumberByClazz(number.toString(), clazz)).collect(Collectors.toList()); return sourceClazzCollection.equals(targetClazzCollection); }  static Range<Comparable<?>> safeIntersection(final Range<Comparable<?>> range, final Range<Comparable<?>> connectedRange); static Range<Comparable<?>> safeClosed(final Comparable<?> lowerEndpoint, final Comparable<?> upperEndpoint); static boolean safeContains(final Range<Comparable<?>> range, final Comparable<?> endpoint); static boolean safeEquals(final Collection<Comparable<?>> sourceCollection, final Collection<Comparable<?>> targetCollection);  }
@Test public void assertSafeEqualsForInteger() { List<Comparable<?>> sourceCollection = Lists.newArrayList(10, 12); List<Comparable<?>> targetCollection = Lists.newArrayList(10, 12); assertTrue(SafeNumberOperationUtils.safeEquals(sourceCollection, targetCollection)); }
@Test public void assertSafeEqualsForLong() { List<Comparable<?>> sourceCollection = Lists.newArrayList(10, 12); List<Comparable<?>> targetCollection = Lists.newArrayList(10L, 12L); assertTrue(SafeNumberOperationUtils.safeEquals(sourceCollection, targetCollection)); }
@Test public void assertSafeEqualsForBigInteger() { List<Comparable<?>> sourceCollection = Lists.newArrayList(10, 12); List<Comparable<?>> targetCollection = Lists.newArrayList(BigInteger.valueOf(10), BigInteger.valueOf(12L)); assertTrue(SafeNumberOperationUtils.safeEquals(sourceCollection, targetCollection)); }
@Test public void assertSafeEqualsForFloat() { List<Comparable<?>> sourceCollection = Lists.newArrayList(10.01F, 12.01F); List<Comparable<?>> targetCollection = Lists.newArrayList(10.01F, 12.01F); assertTrue(SafeNumberOperationUtils.safeEquals(sourceCollection, targetCollection)); }
@Test public void assertSafeEqualsForDouble() { List<Comparable<?>> sourceCollection = Lists.newArrayList(10.01, 12.01); List<Comparable<?>> targetCollection = Lists.newArrayList(10.01F, 12.01); assertTrue(SafeNumberOperationUtils.safeEquals(sourceCollection, targetCollection)); }
@Test public void assertSafeEqualsForBigDecimal() { List<Comparable<?>> sourceCollection = Lists.newArrayList(10.01, 12.01); List<Comparable<?>> targetCollection = Lists.newArrayList(BigDecimal.valueOf(10.01), BigDecimal.valueOf(12.01)); assertTrue(SafeNumberOperationUtils.safeEquals(sourceCollection, targetCollection)); }