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

1234567891011121314151617181920212223242526272829303132333435363738
  1. class Pair {
  2. private final int x;
  3. private final int y;
  4. Pair(final int x, final int y) {
  5. this.y = y;
  6. this.x = x;
  7. }
  8. int getX() {
  9. return x;
  10. }
  11. int getY() {
  12. return y;
  13. }
  14. @Override
  15. public boolean equals(final Object o) {
  16. if (this == o) return true;
  17. if (o == null || getClass() != o.getClass()) return false;
  18. Pair pair = (Pair) o;
  19. return x == pair.x && y == pair.y;
  20. }
  21. @Override
  22. public int hashCode() {
  23. int result = x;
  24. result = 31 * result + y;
  25. return result;
  26. }
  27. }