public T set(int index, T element) { T value = list.set(index, element); collectionSupport.fireUpdated(this, Collections.singleton(element), index, index); return value; }
public boolean add(T o) { boolean added = collection.add(o); int index = collection instanceof List<?> ? size() : -1; if (added) { collectionSupport.fireAdded(this,Collections.singleton(o), index, index); } else { collectionSupport.fireUpdated(this,Collections.singleton(o), index, index); } return added; } public boolean addAll(Collection<? extends T> c) {
public boolean addAll(Collection<? extends T> c) { if (!collectionSupport.hasListeners()) return collection.addAll(c); int max = c.size(); Collection<T> addedElements = new ArrayList<T>(max), updatedElements = new ArrayList<T>(max); for (T t : c) { (collection.add(t) ? addedElements : updatedElements).add(t); } int firstIndex = collection instanceof List<?> ? size() : -1, lastIndex = firstIndex < 0 ? -1 : firstIndex + addedElements.size() - 1; collectionSupport.fireAdded(this, addedElements, firstIndex, lastIndex); collectionSupport.fireUpdated(this, updatedElements, firstIndex, lastIndex); return !addedElements.isEmpty(); } public void clear() {
void propagateUpdated(K key, V oldValue, V newValue) { if (keySet != null) keySet.collectionSupport.fireUpdated(keySet, Collections.singleton(key)); boolean different = !oldValue.equals(newValue); if (entrySet != null) { Collection<Map.Entry<K, V>> newEntries = Collections.singleton((Map.Entry<K, V>)new UnmodifiableEntry<K,V>(key, newValue)); if (different) { Collection<Map.Entry<K, V>> oldEntries = Collections.singleton((Map.Entry<K, V>)new UnmodifiableEntry<K,V>(key, oldValue)); entrySet.collectionSupport.fireRemoved(entrySet, oldEntries); entrySet.collectionSupport.fireAdded(entrySet, newEntries); } else { entrySet.collectionSupport.fireUpdated(entrySet, newEntries); } } if (values != null) { if (different) { valuesSupport.fireRemoved(values, Collections.singleton(oldValue)); valuesSupport.fireAdded(values, Collections.singleton(newValue)); } else { valuesSupport.fireUpdated(values, Collections.singleton(newValue)); } } }
@Override public void collectionChanged(CollectionEvent<T> e) { switch(e.getType()){ case ADDED: ls.fireAdded(CompoundListenableCollection.this, e.getElements()); break; case REMOVED: ls.fireRemoved(CompoundListenableCollection.this, e.getElements()); break; case UPDATED: ls.fireUpdated(CompoundListenableCollection.this, e.getElements()); break; default: break; }//end EventTypes }}; private final CollectionListener<ListenableCollection<T>> outerListener = new CollectionListener<ListenableCollection<T>>(){