Skip to content

Commit

Permalink
Merge pull request #50 from locationtech/feature/projection-hashCode
Browse files Browse the repository at this point in the history
Override Projection hashCode method
  • Loading branch information
echeipesh authored Aug 26, 2019
2 parents 73d0095 + 41350b3 commit 0c6669f
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.locationtech.proj4j.units.Units;

import java.util.Arrays;
import java.util.Objects;

/**
* Represents a projected or geodetic geospatial coordinate system,
Expand Down Expand Up @@ -134,4 +135,9 @@ public boolean equals(Object that) {
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(datum, proj);
}
}
6 changes: 6 additions & 0 deletions src/main/java/org/locationtech/proj4j/datum/Datum.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.locationtech.proj4j.ProjCoordinate;

Expand Down Expand Up @@ -264,4 +265,9 @@ public void shift(ProjCoordinate xy) {
public void inverseShift(ProjCoordinate xy) {
Grid.shift(grids, true, xy);
}

@Override
public int hashCode() {
return Objects.hash(ellipsoid, grids, getTransformType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.locationtech.proj4j.proj;

import java.util.Objects;

import org.locationtech.proj4j.ProjCoordinate;


Expand Down Expand Up @@ -85,4 +87,9 @@ public boolean equals(Object that) {
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(winkel, super.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.locationtech.proj4j.proj;

import java.util.Objects;

import org.locationtech.proj4j.util.ProjectionMath;

/**
Expand Down Expand Up @@ -85,4 +87,9 @@ public boolean equals(Object that) {
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(mode, sinphi0, cosphi0, mapRadius, super.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package org.locationtech.proj4j.proj;

import java.util.Objects;

import org.locationtech.proj4j.ProjCoordinate;
import org.locationtech.proj4j.ProjectionException;
import org.locationtech.proj4j.util.ProjectionMath;
Expand Down Expand Up @@ -214,5 +216,10 @@ public boolean equals(Object that) {
return (this.heightOfOrbit == p.heightOfOrbit) && super.equals(that);
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(heightOfOrbit, super.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.locationtech.proj4j.proj;

import java.util.Objects;

import org.locationtech.proj4j.ProjCoordinate;
import org.locationtech.proj4j.ProjectionException;

Expand Down Expand Up @@ -97,4 +99,9 @@ public boolean equals(Object that) {
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(m, w, super.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.locationtech.proj4j.proj;

import java.util.Objects;

import org.locationtech.proj4j.ProjCoordinate;
import org.locationtech.proj4j.ProjectionException;
import org.locationtech.proj4j.util.ProjectionMath;
Expand Down Expand Up @@ -95,4 +97,9 @@ public boolean equals(Object that) {
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(rw, super.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.locationtech.proj4j.proj;

import java.util.Objects;

import org.locationtech.proj4j.ProjCoordinate;

public class MolleweideProjection extends PseudoCylindricalProjection {
Expand Down Expand Up @@ -140,4 +142,9 @@ public boolean equals(Object that) {
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(type, cx, cy, cp, super.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.locationtech.proj4j.proj;

import java.util.Objects;

import org.locationtech.proj4j.ProjCoordinate;
import org.locationtech.proj4j.ProjectionException;
import org.locationtech.proj4j.datum.Ellipsoid;
Expand Down Expand Up @@ -243,4 +245,9 @@ public boolean equals(Object that) {
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(Gamma, alpha, lonc, super.hashCode());
}
}
19 changes: 19 additions & 0 deletions src/main/java/org/locationtech/proj4j/proj/Projection.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.locationtech.proj4j.proj;

import java.util.NoSuchElementException;
import java.util.Objects;

import org.locationtech.proj4j.*;
import org.locationtech.proj4j.datum.AxisOrder;
Expand Down Expand Up @@ -820,6 +821,12 @@ public Boolean isGeographic() {
return false;
}

/**
* Represents quality between possible outputs of {@link #project(ProjCoordinate, ProjCoordinate) }.
* Subclasses of Projection should capture additional state that is used in the project method and delgate to base.
*
* Note: The name of the projection is not part of equality.
*/
@Override
public boolean equals(Object that) {
if (this == that) {
Expand Down Expand Up @@ -851,4 +858,16 @@ public boolean equals(Object that) {
}
return false;
}

/**
* Hash of those fields considered in Projection equalituy.
* Subclasses that override equality should override hashCode.
*/
@Override
public int hashCode() {
return Objects.hash(this.getClass(),
ellipsoid, falseNorthing, falseEasting, scaleFactor, fromMetres, trueScaleLatitude,
projectionLatitude, projectionLongitude, projectionLatitude1, projectionLatitude2,
minLatitude, maxLatitude, minLongitude, maxLongitude, axes, unit, primeMeridian);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.locationtech.proj4j.proj;

import java.util.Objects;

import org.locationtech.proj4j.ProjCoordinate;
import org.locationtech.proj4j.ProjectionException;
import org.locationtech.proj4j.util.ProjectionMath;
Expand Down Expand Up @@ -188,4 +190,9 @@ public boolean equals(Object that) {
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(type, super.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.locationtech.proj4j.proj;

import java.util.Objects;

import org.locationtech.proj4j.ProjCoordinate;
import org.locationtech.proj4j.util.ProjectionMath;

Expand Down Expand Up @@ -88,4 +90,9 @@ public boolean equals(Object that) {
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(C_x, C_y, C_p, tan_mode, super.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.locationtech.proj4j.proj;

import java.util.Objects;

import org.locationtech.proj4j.ProjCoordinate;
import org.locationtech.proj4j.ProjectionException;
import org.locationtech.proj4j.util.ProjectionMath;
Expand Down Expand Up @@ -83,4 +85,9 @@ public boolean equals(Object that) {
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(n, super.hashCode());
}
}

0 comments on commit 0c6669f

Please sign in to comment.