This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I'm assuming that when an object is placed into a TreeSet that uses a custom Comparator, it's position is determined by Comparator.compare(). What if the object property that compare() uses changes after the object is already inserted into the set?
For example I may be keeping a TreeSet of Document objects sorted by their lastAccessedDate, and the lastAccessedDate of an object changes. Is there a way of making the TreeSet aware of this, or should I just remove the Document from the TreeSet before changing the date and reinsert it afterwards?
You could get into something tricky that listens for changes (see Observer and Observable), removes the object and reinserts it. Or you could create a new TreeSet from your existing TreeSet to re-sort everything before you read from it again.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi