@Override public boolean add(T o) { synchronized (mutex) { return super.add(o); } } @Override
@Override public boolean addAll(Collection<? extends T> c) { synchronized (mutex) { return super.addAll(c); } } @Override
@Override public void addCollectionListener(CollectionListener<T> l) { synchronized (mutex) { super.addCollectionListener(l); } } @Override
public ListenableCollection<V> values() { if (values == null) { valuesSupport = new ListenableSupport<V>(); values = ListenableCollections.unmodifiableCollection(new DefaultListenableCollection<V>(map.values(), valuesSupport)); } return values; }
@Override public void clear() { synchronized (mutex) { super.clear(); } } @Override
@Override public boolean isEmpty() { synchronized (mutex) { return super.isEmpty(); } }
@Override public boolean containsAll(Collection<?> c) { synchronized (mutex) { return super.containsAll(c); } } @Override
@Override public boolean contains(Object o) { synchronized (mutex) { return super.contains(o); } } @Override
@Override public boolean equals(Object obj) { synchronized (mutex) { return super.equals(obj); } } @Override
@Override public int hashCode() { synchronized (mutex) { return super.hashCode(); } } @Override
/** * Wraps a collection in a listenable collection.<br> * The type of the listenable collection returned will depend on that of the provided collection : * <ul> * <li>wrapping a Set<T> will return a ListenableSet<T>, using ListenableCollections.listenableSet(Set<T>)</li> * <li>wrapping a List<T> will return a ListenableList<T>, using ListenableCollections.listenableList(List<T>)</li> * <li>wrapping a ListenableCollection<T> will return the same object</li> * <li>otherwise a instance of a ListenableCollection<T> will be returned.</li> * </ul> * @param <T> component type * @param collectionToWrap * @return listenable collection that uses the provided collection as storage */ public static final <T> ListenableCollection<T> listenableCollection(Collection<T> collectionToWrap) { if (collectionToWrap instanceof ListenableCollection<?>) return (ListenableCollection<T>)collectionToWrap; if (collectionToWrap instanceof Set<?>) { return listenableSet((Set<T>)collectionToWrap); } else if (collectionToWrap instanceof List<?>) { return listenableList((List<T>)collectionToWrap); } return new DefaultListenableCollection<T>(collectionToWrap); }