Пример #1
0
 public boolean add(Object o) {
   getterCalled();
   boolean changed = wrappedSet.add(o);
   if (changed)
     fireSetChange(Diffs.createSetDiff(Collections.singleton(o), Collections.EMPTY_SET));
   return changed;
 }
Пример #2
0
 public void clear() {
   getterCalled();
   if (!wrappedSet.isEmpty()) {
     Set removals = wrappedSet;
     wrappedSet = new IdentitySet();
     fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals));
   }
 }
Пример #3
0
 public boolean addAll(Collection c) {
   getterCalled();
   Set additions = new IdentitySet();
   for (Iterator iterator = c.iterator(); iterator.hasNext(); ) {
     Object element = iterator.next();
     if (wrappedSet.add(element)) additions.add(element);
   }
   boolean changed = !additions.isEmpty();
   if (changed) fireSetChange(Diffs.createSetDiff(additions, Collections.EMPTY_SET));
   return changed;
 }
Пример #4
0
 public boolean removeAll(Collection c) {
   getterCalled();
   Set removals = new IdentitySet();
   for (Iterator iterator = c.iterator(); iterator.hasNext(); ) {
     Object element = iterator.next();
     if (wrappedSet.remove(element)) removals.add(element);
   }
   boolean changed = !removals.isEmpty();
   if (changed) fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals));
   return changed;
 }
Пример #5
0
 public boolean retainAll(Collection c) {
   getterCalled();
   Set removals = new IdentitySet();
   Object[] toRetain = c.toArray();
   outer:
   for (Iterator iterator = wrappedSet.iterator(); iterator.hasNext(); ) {
     Object element = iterator.next();
     // Cannot rely on c.contains(element) because we must compare
     // elements using IElementComparer.
     for (int i = 0; i < toRetain.length; i++) {
       if (element == toRetain[i]) continue outer;
     }
     iterator.remove();
     removals.add(element);
   }
   boolean changed = !removals.isEmpty();
   if (changed) fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals));
   return changed;
 }