lots of exercises in java... from https://github.com/exercism/java

GridPosition.java 840B

123456789101112131415161718192021222324252627282930
  1. final class GridPosition {
  2. final int x;
  3. final int y;
  4. GridPosition(final int x, final int y) {
  5. this.x = x;
  6. this.y = y;
  7. }
  8. /*
  9. * This equals method is of deliberately narrow scope (only allows comparison with another GridPosition) to increase
  10. * readability. In general, one should provide a full implementation of Object.equals(Object obj) and a
  11. * corresponding implementation of Object.hashCode(). See
  12. *
  13. * https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals(java.lang.Object)
  14. *
  15. * and
  16. *
  17. * https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#hashCode()
  18. *
  19. * for more information.
  20. */
  21. boolean equals(final GridPosition gridPosition) {
  22. return this.x == gridPosition.x && this.y == gridPosition.y;
  23. }
  24. }