class WordLocation { private final Pair startCoord; private final Pair endCoord; WordLocation(final Pair startCoord, final Pair endCoord) { this.startCoord = startCoord; this.endCoord = endCoord; } @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; WordLocation that = (WordLocation) o; return startCoord.equals(that.startCoord) && endCoord.equals(that.endCoord); } @Override public int hashCode() { int result = startCoord.hashCode(); result = 31 * result + endCoord.hashCode(); return result; } }