HashSet.contains not working as expected?

I have a HashSet<Face>. Here's face:
    private static class Face {
        public Vertex[] vertices;

        public Face(Vertex[] vertices) {
            this.vertices = vertices;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Face face = (Face) o;
            return Arrays.deepEquals(Arrays.stream(vertices)
                    .sorted(Comparator.comparingInt(v -> Arrays.hashCode(v.vertex)))
                    .toArray(Vertex[]::new), Arrays.stream(face.vertices)
                    .sorted(Comparator.comparingInt(v -> Arrays.hashCode(v.vertex)))
                    .toArray(Vertex[]::new));
        }

        @Override
        public int hashCode() {
            return Arrays.hashCode(vertices);
        }

        @Override
        public String toString() {
            return "Face{" +
                    "vertices=" + Arrays.toString(vertices) +
                    '}';
        }
    }

If I create "idential" faces (the texCoords and vertex order aren't same, but have same vertices), Face.equals returns expected value. However, if I do that for a HashSet, it doesn't work. An ArrayList works fine, but I need a Set. What can I do to fix?
Was this page helpful?