public static <U,V> Collection<V> adapt(Collection<U> col, Adapter<U, V> adapter) { return new AdaptedCollection<U, V>(col, adapter); }
void propagateRemoved(Collection<Map.Entry<K, V>> entries) { if (keySet != null) keySet.collectionSupport.fireRemoved(keySet, new AdaptedCollection<Map.Entry<K,V>, K>(entries, entryToKeyAdapter)); if (entrySet != null) { entrySet.collectionSupport.fireRemoved(entrySet, entries); } if (values != null) { valuesSupport.fireRemoved(values, new AdaptedCollection<Map.Entry<K,V>, V>(entries, entryToValueAdapter)); } }
public void addCollectionListener(CollectionListener<V> l) { if (collectionSupport == null) { collectionSupport = new ListenableSupport<V>(); if (collection instanceof ListenableCollection<?>) { ((ListenableCollection<U>)collection).addCollectionListener(new CollectionListener<U>() { public void collectionChanged(CollectionEvent<U> e) { // Do not propagate the event if we triggered it if (currentlyCausingChange) return; // Only propagate if someone is listening (CollectionSupport already tries not to fire anything when there is no listener, but here we are trying to avoid to create the wrapped elements collection) if (collectionSupport == null || !collectionSupport.hasListeners()) return; // Adapt the collection of changed / added / removed elements in the event collectionSupport.fireEvent( AdaptedCollection.this, new AdaptedCollection<U, V>(e.getElements(), AdaptedCollection.this.forwardAdapter, AdaptedCollection.this.backwardAdapter), e.getType(), e.getFirstIndex(), e.getLastIndex()); } }); } } collectionSupport.addCollectionListener(l); }
public void collectionChanged(CollectionEvent<U> e) { // Do not propagate the event if we triggered it if (currentlyCausingChange) return; // Only propagate if someone is listening (CollectionSupport already tries not to fire anything when there is no listener, but here we are trying to avoid to create the wrapped elements collection) if (collectionSupport == null || !collectionSupport.hasListeners()) return; // Adapt the collection of changed / added / removed elements in the event collectionSupport.fireEvent( AdaptedCollection.this, new AdaptedCollection<U, V>(e.getElements(), AdaptedCollection.this.forwardAdapter, AdaptedCollection.this.backwardAdapter), e.getType(), e.getFirstIndex(), e.getLastIndex()); } });
relevantPositioned = PredicatedCollection.predicatedCollection( new AdaptedCollection<PositionedRenderable,Positionable>(getVisibleWorldObjectList(),Util.bidi2Backward(castingAdapter),Util.bidi2Forward(castingAdapter)), new InstanceofPredicate(PositionedRenderable.class)); setCamera(camera);