This code does not do what you need to:
public boolean equals(Dog d){ return this.size.equals(d.size); }
This is not an override of Object.equals that uses a HashSet. You need:
@Override public boolean equals(Object d){ if (!(d instanceof Dog)) { return false; } Dog dog = (Dog) d; return this.size.equals(dog.size); }
Note that using the @Override annotation @Override you ask the compiler to verify that you are actually overriding the method.
EDIT: As already noted, you also need to override hashCode in a way that is compatible with your equals method. Given that you are checking for equality in size, the simplest option would be:
@Override public int hashCode() { return size.hashCode(); }
source share