VisionSet said:
I believe my problem has something to do with the underlying method of
removal.
I am using a Set and (though ill advised) the contents are mutable.
I am mutating objects during iteration and the underlying remove(object)
method is not working correctly for some reason, if I ditch my equals &
hashCode methods it works fine.
So I think those are the culprit.
The culprit is the fact that you are mutating the contents without
removing them from the container. You cannot change the the items in a
HashSet (or the keys for a HashMap which is actually what HashSet uses
for its implementation) in a way that changes the outcome of the equals
or hashcode method. To change the value, you must remove it, change it
and then put it back. Otherwise you will not be able to find it. HashMap
rely on equals and hashCode to be able to retrieve the item.
The same type of thing also applies to TreeSet and TreeMap, but the
important method there is the compareTo method.
Unfortunately you can't do this type of operation using an iterator
because adding an item will kill any iterators with a
ConcurrentModificationException.
By "ditching" your equals and hashCode methods you use the default ones
and their outcomes can never be changed so the fact that you mutate the
object does not result in unretreivable items. But that also means you
can get multiple objects in the set with the same "value". Whether this
is appropriate depends on your application.
-- Dale King