@Test public void testCompare_resultMustBeZero() { assertEquals(0, this.comparator.compare(zero, zero)); assertEquals(0, this.comparator.compare(p100, p90)); assertEquals(0, this.comparator.compare(p90, p100)); assertEquals(0, this.comparator.compare(n100, n90)); assertEquals(0, this.comparator.compare(n90, n100)); assertEquals(0, this.comparator.compare(p89, p90)); assertEquals(0, this.comparator.compare(p90, p89)); assertEquals(0, this.comparator.compare(n89, n90)); assertEquals(0, this.comparator.compare(n90, n89)); }
@Override public int compare(Number o1, Number o2) { BigDecimal diff = new BigDecimal(String.valueOf(o1)) .subtract(new BigDecimal(String.valueOf(o2))); if (diff.signum() == 0) { return 0; } BigDecimal bd1 = new BigDecimal(String.valueOf(o1)); BigDecimal bd2 = new BigDecimal(String.valueOf(o2)); BigDecimal greater = bd1.abs().compareTo(bd2.abs()) > 0 ? bd1 : bd2; if (greater.signum() != 0) { BigDecimal relDiff = diff.multiply(ONE_HUNDRED).divide(greater, 2, BigDecimal.ROUND_HALF_UP); if (relDiff.abs().compareTo(this.maxDiff) <= 0) return 0; } return bd1.compareTo(bd2); }
RelDiffNumberComparator implements Comparator<Number> { @Override public int compare(Number o1, Number o2) { BigDecimal diff = new BigDecimal(String.valueOf(o1)) .subtract(new BigDecimal(String.valueOf(o2))); if (diff.signum() == 0) { return 0; } BigDecimal bd1 = new BigDecimal(String.valueOf(o1)); BigDecimal bd2 = new BigDecimal(String.valueOf(o2)); BigDecimal greater = bd1.abs().compareTo(bd2.abs()) > 0 ? bd1 : bd2; if (greater.signum() != 0) { BigDecimal relDiff = diff.multiply(ONE_HUNDRED).divide(greater, 2, BigDecimal.ROUND_HALF_UP); if (relDiff.abs().compareTo(this.maxDiff) <= 0) return 0; } return bd1.compareTo(bd2); } }
RelDiffNumberComparator implements Comparator<Number> { @Override public int compare(Number o1, Number o2) { BigDecimal diff = new BigDecimal(String.valueOf(o1)) .subtract(new BigDecimal(String.valueOf(o2))); if (diff.signum() == 0) { return 0; } BigDecimal bd1 = new BigDecimal(String.valueOf(o1)); BigDecimal bd2 = new BigDecimal(String.valueOf(o2)); BigDecimal greater = bd1.abs().compareTo(bd2.abs()) > 0 ? bd1 : bd2; if (greater.signum() != 0) { BigDecimal relDiff = diff.multiply(ONE_HUNDRED).divide(greater, 2, BigDecimal.ROUND_HALF_UP); if (relDiff.abs().compareTo(this.maxDiff) <= 0) return 0; } return bd1.compareTo(bd2); } RelDiffNumberComparator(int i);  RelDiffNumberComparator(BigDecimal maxDiff); }
RelDiffNumberComparator implements Comparator<Number> { @Override public int compare(Number o1, Number o2) { BigDecimal diff = new BigDecimal(String.valueOf(o1)) .subtract(new BigDecimal(String.valueOf(o2))); if (diff.signum() == 0) { return 0; } BigDecimal bd1 = new BigDecimal(String.valueOf(o1)); BigDecimal bd2 = new BigDecimal(String.valueOf(o2)); BigDecimal greater = bd1.abs().compareTo(bd2.abs()) > 0 ? bd1 : bd2; if (greater.signum() != 0) { BigDecimal relDiff = diff.multiply(ONE_HUNDRED).divide(greater, 2, BigDecimal.ROUND_HALF_UP); if (relDiff.abs().compareTo(this.maxDiff) <= 0) return 0; } return bd1.compareTo(bd2); } RelDiffNumberComparator(int i);  RelDiffNumberComparator(BigDecimal maxDiff); @Override int compare(Number o1, Number o2); @Override String toString(); }
RelDiffNumberComparator implements Comparator<Number> { @Override public int compare(Number o1, Number o2) { BigDecimal diff = new BigDecimal(String.valueOf(o1)) .subtract(new BigDecimal(String.valueOf(o2))); if (diff.signum() == 0) { return 0; } BigDecimal bd1 = new BigDecimal(String.valueOf(o1)); BigDecimal bd2 = new BigDecimal(String.valueOf(o2)); BigDecimal greater = bd1.abs().compareTo(bd2.abs()) > 0 ? bd1 : bd2; if (greater.signum() != 0) { BigDecimal relDiff = diff.multiply(ONE_HUNDRED).divide(greater, 2, BigDecimal.ROUND_HALF_UP); if (relDiff.abs().compareTo(this.maxDiff) <= 0) return 0; } return bd1.compareTo(bd2); } RelDiffNumberComparator(int i);  RelDiffNumberComparator(BigDecimal maxDiff); @Override int compare(Number o1, Number o2); @Override String toString();  }