I am using a TreeSet in a class that extends AbstractListModel. It seems that the TreeSet.remove() and TreeSet.contains() is not finding the object. If I run the code below, the element is not found (sometimes).
public boolean removeElement(VariableInfo element){
boolean removed = model.remove(element);
if(removed){
fireContentsChanged(this, 0, getSize());
}
return removed;
}
If I run this code, however, the element is found. (The code below will fail if the uncommented line is used.) Any ideas why this is happening? I don't want to use the code below because it requires iterating over all the elements in the list.
public boolean removeElement(VariableInfo element){
for(VariableInfo v : model){
if(v.equals(element)){
return model.remove(v);
//return model.remove(element); //will also fail if using this line instead of previous one
}
}
return false;
}