1

How do I override the hashCode() of the Graphstream Node object?

I am inserting the Nodes into a HashSet.

HashSet<Node> set = new HashSet<Node>();

Quaxton Hale
  • 2,460
  • 5
  • 40
  • 71

1 Answers1

2

You may inherit from Node to extend the objects hash in this class using Objects.hash(Object...). Just throw into this method whatever you want to have hashed together ...

class MyNode extends Node {

// whatever floats you boat here

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), other);
    }

    @Override
    public boolean equals(Object o) {
    // hashCode() and equals() overrides should always appear together
    }
}

Maybe have a look here

EDIT: Dont' forget the equals() override!

Community
  • 1
  • 1
Horst
  • 334
  • 1
  • 12