SurfaceValue { public static SurfaceValue plus(final SurfaceValue value1, final SurfaceValue value2) { ArgumentChecker.notNull(value1, "Surface value 1"); ArgumentChecker.notNull(value2, "Surface value 2"); final HashMap<DoublesPair, Double> plus = new HashMap<>(value1._data); for (final DoublesPair p : value2._data.keySet()) { if (value1._data.containsKey(p)) { plus.put(p, value2._data.get(p) + value1._data.get(p)); } else { plus.put(p, value2._data.get(p)); } } return new SurfaceValue(plus); } 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 plus() { 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 surfPlus1 = SurfaceValue.plus(surf1, point2, value2); assertEquals("Surface value - plus", 2, surfPlus1.getMap().size()); assertTrue("Surface value - plus", surfPlus1.getMap().containsKey(point1)); assertTrue("Surface value - plus", surfPlus1.getMap().containsKey(point2)); assertEquals("Surface value - plus", value1, surfPlus1.getMap().get(point1), TOLERANCE); assertEquals("Surface value - plus", value2, surfPlus1.getMap().get(point2), TOLERANCE); SurfaceValue surf2 = SurfaceValue.from(point2, value2); SurfaceValue surfPlus2 = SurfaceValue.plus(surf1, surf2); assertEquals("Surface value - plus", 2, surfPlus2.getMap().size()); assertTrue("Surface value - plus", surfPlus2.getMap().containsKey(point1)); assertTrue("Surface value - plus", surfPlus2.getMap().containsKey(point2)); assertEquals("Surface value - plus", value1, surfPlus2.getMap().get(point1), TOLERANCE); assertEquals("Surface value - plus", value2, surfPlus2.getMap().get(point2), TOLERANCE); assertTrue("Surface value - plus", SurfaceValue.compare(SurfaceValue.plus(surfPlus2, surfPlus2), SurfaceValue.multiplyBy(surfPlus2, 2), TOLERANCE)); DoublesPair point3 = DoublesPair.of(2.0, 2.0); double value3 = 12.345; SurfaceValue surf3 = SurfaceValue.from(point3, value3); assertTrue("Surface value - plus", SurfaceValue.compare(SurfaceValue.plus(surfPlus2, point3, value3), SurfaceValue.plus(surfPlus2, surf3), TOLERANCE)); }