Comments (9)
I used all the field in the equals override, and in the same order, to increase maintainability. Should I do the same for the 10 subclasses that override equals?
That would be my assumption, but I defer to the others here.
I wonder if we should consider using this or something similar?
https://jqno.nl/equalsverifier/
from proj4j.
@pomadchin I didn't notice the name was not used intententionally, thanks for pointing that out.
Using that class directly would add a dependency to this project, which I would like to avoid. I usually use IntelliJ to generate equals
and hashCode
overrides, but for a class this complicated it results in something like this: https://github.com/Neutius/proj4j/commit/887753c9c412cb6d64b8a93fc3cd2109e9ee9c7e
I'm pretty sure we could find a way to make readable and maintainable code without adding a dependency.
from proj4j.
@Neutius ah yeah, I didn’t mean to add an extra dependency, but to use this class as an example of how we could make a more consistent hash code generation.
from proj4j.
Is it a fair statement to say that the state used to compute hashCode
should be exactly the same state used to compute equals
? If so, I'd argue hashCode
should be implemented in the concrete specializations rather than the base class, side-by-side with equals
.
As a snarky aside, the fact that these classes are mutable makes me shudder to think that anyone would ever put them in a Hash{Set|Table}
etc.
from proj4j.
I made an attempt to generate a hashCode
override for the Projection class, but I simply lack the domain/GIS/mathematical knowledge to know what I'm doing.
I did notice the current equals
override doesn't check for the name
field, which might be an oversight. There are about a dozen other fields that may or not be relevant for overriding equals
and hashCode
, I have no way of telling.
from proj4j.
@Neutius it doesn't compare by the name
intentionally, read through this PR description. It can be different for the same projection depending on how the instance of the projection was created.
P.S. There is a useful class we can probably use to simplify the code to write hashCode
function overloads.
from proj4j.
I fiddled around a bit, still not happy with it, but at least it's something: https://github.com/Neutius/proj4j/commit/c3f48a0312180fa82c9d8a372d20b5c2c448d176
from proj4j.
I fully agree with you on the first part. In my attempt, I included every field included in the equals
override. We should absolutely override hashCode
in the ten subclasses that override equals
. Most subclasses don't, I guess the override in the Projection base class is a good fit for those?
I could generate and refactor hashCode
overrides for those ten subclasses, but again, I lack the domain/GIS/mathematical knowledge to understand the contents of what I'm doing. I could probably deliver some decent Java code, though.
Edit: my co-worker pointed out I should use the Objects.hash method, which results in something like this: https://github.com/Neutius/proj4j/commit/0679ed05be0385cc50d7f54245fa2357cfd32a0d
I used all the field in the equals
override, and in the same order, to increase maintainability. Should I do the same for the 10 subclasses that override equals
?
from proj4j.
@metasim dunno; I will look into it, thanks for the link. I think it is a critical issue now, I will have to look into it.
from proj4j.
Related Issues (20)
- How I can use vunits in android? HOT 1
- Will there be support for +geoidgrids ? its commonly used for height transformation HOT 1
- VN2000 Error Exception in thread "main" java.lang.IllegalStateException: Latitude is out of range: 9738.514891355962
- Transforming from "EPSG:4326" to "EPSG:3857" results in precision error
- Reprojection results seem to be too imprecise
- Support for polar stereographic with alternate scales HOT 4
- altitude not working when Projecting HOT 1
- rhealpix is not supported HOT 1
- Datum.isEqual maybe have a bug
- Unknown projection: longlat HOT 22
- gtx files cannot be used?
- reprojection from epsg:31370 to epsg:3857 is inaccurate HOT 1
- Transverse Mercator Projection test failed HOT 1
- Equidistant Azimuthal (ESRI:54032) test failed HOT 1
- Robinson projection (ESRI:54030) test failed HOT 2
- UnknownAuthorityCodeException: EPSG:9054 HOT 3
- ntv2 grid support
- Proj4j should not use the Apache License if it contains the EPSG data set HOT 16
- In release 1.2.0, the pom file contains incorrect version '1.2.0-SNAPSHOT' HOT 14
- Improve proj4j tests to reflect the recent changes and the moved out EPSG resources
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proj4j.