StringAmount { public static boolean compare(final StringAmount value1, final StringAmount value2, final double tolerance) { final Set<String> set1 = value1._data.keySet(); final Set<String> set2 = value2._data.keySet(); if (!set1.equals(set2)) { return false; } for (final String p : set1) { if (Math.abs(value1._data.get(p) - value2._data.get(p)) > tolerance) { return false; } } return true; } StringAmount(); private  StringAmount(final HashMap<String, Double> map); static StringAmount from(final String point, final Double value); static StringAmount from(final Map<String, Double> map); static StringAmount from(final StringAmount surface); HashMap<String, Double> getMap(); void add(final String point, final Double value); static StringAmount plus(final StringAmount value1, final StringAmount value2); static StringAmount plus(final StringAmount stringValue, final String point, final Double value); static StringAmount multiplyBy(final StringAmount stringValue, final double factor); static boolean compare(final StringAmount value1, final StringAmount value2, final double tolerance);  }
@Test public void compare() { String point1 = "Point 1"; double value1 = 2345.678; StringAmount surf1 = StringAmount.from(point1, value1); String point2 = "Point 2"; double value2 = 10 * Math.E; StringAmount surf2 = StringAmount.from(point2, value2); StringAmount surfPlus1 = StringAmount.plus(surf1, surf2); StringAmount surfPlus2 = StringAmount.plus(surf2, surf1); assertTrue("Surface value - compare", StringAmount.compare(surfPlus1, surfPlus2, TOLERANCE)); }