/** * {@inheritDoc } */ @Override public int hashCode() { final int PRIME = 31; int result = 1; result = PRIME * result + ((position == null) ? 0 : position.hashCode()); return result; }
/** * Returns {@code true} if the specified object is also a {@linkplain DirectPosition direct * position} with equals {@linkplain #getCoordinate coordinate} and {@linkplain * #getCoordinateReferenceSystem CRS}. * * @param object The object to compare with this position. * @return {@code true} if the given object is equals to this position. */ @Override public boolean equals(final Object object) { if (object instanceof DirectPosition) { final DirectPosition that = (DirectPosition) object; final int dimension = getDimension(); if (dimension == that.getDimension()) { for (int i = 0; i < dimension; i++) { if (!Utilities.equals(this.getOrdinate(i), that.getOrdinate(i))) { return false; } } if (Utilities.equals( this.getCoordinateReferenceSystem(), that.getCoordinateReferenceSystem())) { assert hashCode() == that.hashCode() : this; return true; } } } return false; } }
&& Utilities.equals(other.getOrdinate(1), y) && Utilities.equals(other.getCoordinateReferenceSystem(), crs)) { assert hashCode() == other.hashCode() : this; return true;
/** * Compares this point with the specified object for equality. If the given object implements * the {@link DirectPosition} interface, then the comparison is performed as specified in its * {@link DirectPosition#equals} contract. * * @param object The object to compare with this position. * @return {@code true} if the given object is equals to this position. */ @Override public boolean equals(final Object object) { /* * If the other object implements the DirectPosition interface, performs * the comparaison as specified in DirectPosition.equals(Object) contract. */ if (object instanceof DirectPosition) { final DirectPosition other = (DirectPosition) object; if (other.getDimension() == 3 && Utilities.equals(other.getOrdinate(0), x) && Utilities.equals(other.getOrdinate(1), y) && Utilities.equals(other.getOrdinate(2), z) && Utilities.equals(other.getCoordinateReferenceSystem(), crs)) { assert hashCode() == other.hashCode() : this; return true; } return false; } return false; }
Objects.equals(other.getCoordinateReferenceSystem(), crs)) assert hashCode() == other.hashCode() : this; return true;
Objects.equals(other.getCoordinateReferenceSystem(), crs)) assert hashCode() == other.hashCode() : this; return true;
that.getCoordinateReferenceSystem())) assert hashCode() == that.hashCode() : this; return true;
that.getCoordinateReferenceSystem())) assert hashCode() == that.hashCode() : this; return true;
/** * Tests {@link DirectPosition2D#equals(Object)} method between different implementations. * The purpose of this test is also to run the assertion in the direct position implementations. */ @Test public void testEquals() { assertTrue(DirectPosition1D .class.desiredAssertionStatus()); assertTrue(GeneralDirectPosition.class.desiredAssertionStatus()); DirectPosition p1 = new DirectPosition1D (48.543261561072285); DirectPosition p2 = new GeneralDirectPosition(48.543261561072285); assertTrue(p1.equals(p2)); assertTrue(p2.equals(p1)); assertEquals(p2.hashCode(), p1.hashCode()); p1.setOrdinate(0, p1.getOrdinate(0) + 1); assertFalse(p1.equals(p2)); assertFalse(p2.equals(p1)); assertFalse(p2.hashCode() == p1.hashCode()); }
/** * Tests {@link DirectPosition2D#equals(Object)} method between different implementations. * The purpose of this test is also to run the assertion in the direct position implementations. */ @Test public void testEquals() { assertTrue(DirectPosition2D .class.desiredAssertionStatus()); assertTrue(GeneralDirectPosition.class.desiredAssertionStatus()); DirectPosition p1 = new DirectPosition2D (48.543261561072285, -123.47009555832284); DirectPosition p2 = new GeneralDirectPosition(48.543261561072285, -123.47009555832284); assertTrue(p1.equals(p2)); assertTrue(p2.equals(p1)); assertEquals(p2.hashCode(), p1.hashCode()); p1.setOrdinate(0, p1.getOrdinate(0) + 1); assertFalse(p1.equals(p2)); assertFalse(p2.equals(p1)); assertFalse(p2.hashCode() == p1.hashCode()); }
@Test public void testNewPointHere() { DirectPosition here = new GeneralDirectPosition(CommonCRS.WGS84.normalizedGeographic()); here.setOrdinate(0, 48.44); here.setOrdinate(1, -123.37); // 48.44,-123.37 Point point = new JTSPoint(here); assertNotNull(point.getCoordinateReferenceSystem()); assertEquals(here.getCoordinateReferenceSystem(), point .getCoordinateReferenceSystem()); assertEquals(here, point.getDirectPosition()); assertEquals(here.hashCode(), point.getDirectPosition().hashCode()); }
@Test public void testNewFactoryPointHere() { PositionFactory gFact = new JTSPositionFactory( CommonCRS.WGS84.normalizedGeographic()); double[] ords = { 48.44, -123.37 }; DirectPosition here = gFact.createDirectPosition(ords); Point point = new JTSPoint(here); assertNotNull(point.getCoordinateReferenceSystem()); assertEquals(here.getCoordinateReferenceSystem(), point .getCoordinateReferenceSystem()); assertEquals(here, point.getDirectPosition()); assertEquals(here.hashCode(), point.getDirectPosition().hashCode()); }
hashCode, object.hashCode()); assertTrue("DirectPosition: shall be equal to itself.", object.equals(object));
@Test public void testWSG843DPoint(){ // Do actually test stuff double[] ords = { 48.44, -123.37, 0.0 }; PositionFactory factory = new JTSPositionFactory(AbstractCRS.castOrCopy(CommonCRS.WGS84.geographic3D()).forConvention(AxesConvention.RIGHT_HANDED)); assertNotNull(factory); DirectPosition here = factory.createDirectPosition(ords); Point point = new JTSPoint(here); assertNotNull(point.getCoordinateReferenceSystem()); assertEquals(here.getCoordinateReferenceSystem(), point .getCoordinateReferenceSystem()); assertEquals(here, point.getDirectPosition()); assertEquals(here.hashCode(), point.getDirectPosition().hashCode()); }
hashCode, object.hashCode()); assertTrue("DirectPosition: must be equals to itself.", object.equals(object));