SurfaceValue { public static boolean compare(final SurfaceValue value1, final SurfaceValue value2, final double tolerance) { final Set<DoublesPair> set1 = value1._data.keySet(); final Set<DoublesPair> set2 = value2._data.keySet(); for (final DoublesPair p : set1) { if (value2._data.get(p) == null && Math.abs(value1._data.get(p)) > tolerance) { return false; } if (value2._data.get(p) != null) { if (Math.abs(value1._data.get(p) - value2._data.get(p)) > tolerance) { return false; } } } for (final DoublesPair p : set2) { if (value1._data.get(p) == null && Math.abs(value2._data.get(p)) > tolerance) { return false; } if (value1._data.get(p) != null) { if (Math.abs(value2._data.get(p) - value1._data.get(p)) > tolerance) { return false; } } } return true; } SurfaceValue(); private  SurfaceValue(final HashMap<DoublesPair, Double> map); static SurfaceValue from(final DoublesPair point, final Double value); static SurfaceValue from(final Map<DoublesPair, Double> map); static SurfaceValue from(final SurfaceValue surface); HashMap<DoublesPair, Double> getMap(); void add(final DoublesPair point, final Double value); int getNumberOfElements(); static SurfaceValue plus(final SurfaceValue value1, final SurfaceValue value2); static SurfaceValue plus(final SurfaceValue surfaceValue, final DoublesPair point, final Double value); static SurfaceValue multiplyBy(final SurfaceValue surfaceValue, final double factor); static boolean compare(final SurfaceValue value1, final SurfaceValue value2, final double tolerance); double toSingleValue(); @Override String toString(); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test public void compare() { DoublesPair point1 = DoublesPair.of(1.0, 2.0); double value1 = 2345.678; SurfaceValue surf1 = SurfaceValue.from(point1, value1); DoublesPair point2 = DoublesPair.of(2.0, Math.PI); double value2 = 10 * Math.E; SurfaceValue surf2 = SurfaceValue.from(point2, value2); SurfaceValue surfPlus1 = SurfaceValue.plus(surf1, surf2); SurfaceValue surfPlus2 = SurfaceValue.plus(surf2, surf1); assertTrue("Surface value - compare", SurfaceValue.compare(surfPlus1, surfPlus2, TOLERANCE)); }