PointND implements Serializable { public void set(int dimension, T coordinate) { coordinates[dimension] = coordinate; } PointND(T... coordinates); int getDimensions(); T get(int dimension); void set(int dimension, T coordinate); void setLocation(T... coordinates); Point2D getPoint2D(int dimX, int dimY); Point2D getPoint2D(); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); static final int X; static final int Y; static final int Z; }
@Test public void testSet() { Double[] coordinates = {1.0, 2.0, 3.0, 4.0}; PointND<Double> p = new PointND<>(coordinates); int dim = 1; p.set(dim, 0.0); assertFalse(coordinates[dim].equals(p.get(dim))); assertEquals(0.0, p.get(dim), DELTA); Double[] coordinatesNew = {0.0, 1.0, 3.0, 2.0}; p.setLocation(coordinatesNew); for (int d = 0; d < coordinates.length; d++) { assertEquals(coordinatesNew[d], p.get(d)); } try { Double[] coordinatesNew2 = {0.0, 1.0}; p.setLocation(coordinatesNew2); fail("Expected IllegalArgumentException exception."); } catch (IllegalArgumentException e) { } }