PointND implements Serializable { public Point2D getPoint2D(int dimX, int dimY) { if (getDimensions() < 2) { throw new ArrayIndexOutOfBoundsException( "Can't create two-dimensional point from " + getDimensions() + "D data."); } return new Point2D.Double( get(dimX).doubleValue(), get(dimY).doubleValue()); } 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 testPoint2D() { PointND<Double> p4 = new PointND<>(1.0, 2.0, 3.0, 4.0); assertEquals(new Point2D.Double(1.0, 2.0), p4.getPoint2D()); assertEquals(new Point2D.Double(2.0, 3.0), p4.getPoint2D(1, 2)); PointND<Double> p1 = new PointND<>(1.0); try { p1.getPoint2D(); fail("Expected ArrayIndexOutOfBoundsException exception."); } catch (ArrayIndexOutOfBoundsException e) { } }