StringAmount { public static StringAmount plus(final StringAmount value1, final StringAmount value2) { ArgumentChecker.notNull(value1, "Surface value 1"); ArgumentChecker.notNull(value2, "Surface value 2"); final HashMap<String, Double> plus = new HashMap<>(value1._data); for (final String 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 StringAmount(plus); } 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 plus() { String point1 = "Point 1"; double value1 = 2345.678; StringAmount surf1 = StringAmount.from(point1, value1); String point2 = "Point 2"; double value2 = 10 * Math.E; StringAmount surfPlus1 = StringAmount.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); StringAmount surf2 = StringAmount.from(point2, value2); StringAmount surfPlus2 = StringAmount.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", StringAmount.compare(StringAmount.plus(surfPlus2, surfPlus2), StringAmount.multiplyBy(surfPlus2, 2), TOLERANCE)); String point3 = "Point 3"; double value3 = 12.345; StringAmount surf3 = StringAmount.from(point3, value3); assertTrue("Surface value - plus", StringAmount.compare(StringAmount.plus(surfPlus2, point3, value3), StringAmount.plus(surfPlus2, surf3), TOLERANCE)); }