I have Clips that can be added to or removed from any number of Lines. When I add the Clip, I put it into a ClipHolder so I can keep some bounds information with it which is specific to the Line / Clip relationship.The trouble comes when I want to remove a Clip from the Line. I need to remove the ClipHolder in the associatedClips Set which holds the Clip, but I cannot just call associateClips.remove(Clip) (obviously as the set is holding ClipHolders, not Clips) so I am stuck iterating through the set, and searching one by one for it (see the removeClip method below.)Within the Line class the ClipHolder class is simply an implementation detail that the user should not have to worry about. They should only have to worry about their Clips which are a separate class.I would like to avoid burdening the users of this class with requiring them to choose a unique token to identify each instance of Clip. I think that  having a reference to the Clip should be enough. (Is this reasonable?)Does anyone have a good way of cleaning this up?class Line {    .....    private class ClipHolder{        Clip c;        Bounds bounds;    }    private TreeSet<ClipHolder> associatedClips = new TreeSet<ClipHolder>();    public void addClip(Clip c){        ClipHolder holder = new ClipHolder();        holder.c = c;        calculateBounds(holder);        associatedClips.add(holder);    }    public void removeClip(Clip c){        for (ClipHolder ih: associatedClips ) {            if(ih.c == c){                associatedClips.remove(ih);                break;            }        }    }}
Removing an object which is wrapped in another object from a collection
java;collections