com.threerings.util
Class WeakObserverSet<T>

java.lang.Object
  extended by com.threerings.util.WeakObserverSet<T>

public class WeakObserverSet<T>
extends Object

Much like WeakObserverList, but provides faster addition and removal in exchange for using additional memory and generating additional garbage (the iterator) on notification.


Nested Class Summary
static interface WeakObserverSet.ObserverOp<T>
          Instances of this interface are used to apply methods to all observers in a set.
protected static class WeakObserverSet.ObserverRef<T>
          Represents a reference to an observer.
 
Field Summary
protected  boolean _dirty
          Set when we need to update the snapshot.
protected  LinkedHashSet<WeakObserverSet.ObserverRef<T>> _set
          The contained set.
protected  WeakObserverSet.ObserverRef<T>[] _snap
          A snapshot of the set.
 
Constructor Summary
WeakObserverSet()
           
 
Method Summary
 boolean add(T observer)
          Adds an observer to the set.
 void apply(WeakObserverSet.ObserverOp<T> obop)
          Applies the specified operation to all observers in the set.
protected static
<T> boolean
checkedApply(WeakObserverSet.ObserverOp<T> obop, T obs)
          Applies the operation to the observer, catching and logging any exceptions thrown in the process.
 boolean isEmpty()
          Checks whether the set is empty.
static
<T> WeakObserverSet<T>
newSet()
          A convenience method for creating an observer set that avoids duplicating the type parameter on the right hand side.
 boolean remove(T observer)
          Removes an observer from the set.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_set

protected LinkedHashSet<WeakObserverSet.ObserverRef<T>> _set
The contained set.


_snap

protected WeakObserverSet.ObserverRef<T>[] _snap
A snapshot of the set.


_dirty

protected boolean _dirty
Set when we need to update the snapshot.

Constructor Detail

WeakObserverSet

public WeakObserverSet()
Method Detail

newSet

public static <T> WeakObserverSet<T> newSet()
A convenience method for creating an observer set that avoids duplicating the type parameter on the right hand side.


add

public boolean add(T observer)
Adds an observer to the set.


remove

public boolean remove(T observer)
Removes an observer from the set.


isEmpty

public boolean isEmpty()
Checks whether the set is empty.


apply

public void apply(WeakObserverSet.ObserverOp<T> obop)
Applies the specified operation to all observers in the set.


toString

public String toString()
Overrides:
toString in class Object

checkedApply

protected static <T> boolean checkedApply(WeakObserverSet.ObserverOp<T> obop,
                                          T obs)
Applies the operation to the observer, catching and logging any exceptions thrown in the process.