danger.util
Class ActiveList.WeakDelegateList

java.lang.Object
  extended by danger.util.SimpleWeakList
      extended by danger.util.ActiveList.WeakDelegateList
All Implemented Interfaces:
ActiveList.Delegate
Direct Known Subclasses:
ActiveFolder.WeakDelegateList
Enclosing interface:
ActiveList


public static class ActiveList.WeakDelegateList
extends SimpleWeakList
implements ActiveList.Delegate

List of delegates which are held onto weakly. Instances of this class are used to hold multiple delegates that have been added to a single list instance. All of the on*() methods call that same method with the same arguments on each of the delegates in the list. Note that the SimpleWeakList.add(java.lang.Object) and SimpleWeakList.remove(java.lang.Object) methods are simply the inherited Object-accepting ones, but the guts of this class assume that the only things ever added are appropriate delegates.


Field Summary
protected  int mIndex
          used while iterating
protected  Object mItem
          used while iterating
protected  Object[] mItems
          used while iterating
protected  ActiveList mList
          used while iterating
protected  int mOperation
          used while iterating
protected static int ON_ITEM_ADDED
           
protected static int ON_ITEM_REMOVED
           
protected static int ON_ITEM_UPDATED
           
protected static int ON_ITEMS_REORDERED
           
protected static int ON_RANGE_ADDED
           
protected static int ON_RANGE_REMOVED
           
 
Constructor Summary
ActiveList.WeakDelegateList()
          Construct an instance with an initial capacity of 4.
ActiveList.WeakDelegateList(int initialCapacity)
          Construct an instance.
 
Method Summary
protected  void accept(Object obj)
          Do the operation for a delegate.
 ActiveList.Delegate getDelegate(int n)
          Get the nth delegate in the list, which may turn out to be a reaped reference.
 void onItemAdded(ActiveList list, Object item, int index)
          This method is called whenever an item is added to an ActiveList instance.
 void onItemRemoved(ActiveList list, Object item, int index)
          This method is called whenever an individual item is removed from an ActiveList instance.
 void onItemsReordered(ActiveList list)
          This method is called whenever items get reordered in an ActiveList instance.
 void onItemUpdated(ActiveList list, Object item, int index)
          This method is called whenever an item is updated.
 void onRangeAdded(ActiveList list, Object[] items, int start)
          This method is called whenever a contiguous range of items is added to an ActiveList instance.
 void onRangeRemoved(ActiveList list, Object[] items, int start)
          This method is called whenever a range of items is removed from an ActiveList instance.
 
Methods inherited from class danger.util.SimpleWeakList
accept, add, contains, forEachAccept, forEachAccept, get, matchesTarget, remove, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ON_ITEM_UPDATED

protected static final int ON_ITEM_UPDATED
See Also:
Constant Field Values

ON_ITEM_ADDED

protected static final int ON_ITEM_ADDED
See Also:
Constant Field Values

ON_ITEM_REMOVED

protected static final int ON_ITEM_REMOVED
See Also:
Constant Field Values

ON_RANGE_ADDED

protected static final int ON_RANGE_ADDED
See Also:
Constant Field Values

ON_RANGE_REMOVED

protected static final int ON_RANGE_REMOVED
See Also:
Constant Field Values

ON_ITEMS_REORDERED

protected static final int ON_ITEMS_REORDERED
See Also:
Constant Field Values

mOperation

protected int mOperation
used while iterating


mList

protected ActiveList mList
used while iterating


mItem

protected Object mItem
used while iterating


mItems

protected Object[] mItems
used while iterating


mIndex

protected int mIndex
used while iterating

Constructor Detail

ActiveList.WeakDelegateList

public ActiveList.WeakDelegateList(int initialCapacity)
Construct an instance.

Parameters:
initialCapacity - initial capacity of the list; it will expand as needed

ActiveList.WeakDelegateList

public ActiveList.WeakDelegateList()
Construct an instance with an initial capacity of 4.

Method Detail

getDelegate

public final ActiveList.Delegate getDelegate(int n)
Get the nth delegate in the list, which may turn out to be a reaped reference.

Parameters:
n - which element to get
Returns:
null-ok; the nth delegate, or null if it was reaped

onItemUpdated

public final void onItemUpdated(ActiveList list,
                                Object item,
                                int index)
Description copied from interface: ActiveList.Delegate
This method is called whenever an item is updated. That is, this is called when an item in an ActiveList instance notifies this instance that is was updated via its update mechanism.

Specified by:
onItemUpdated in interface ActiveList.Delegate
Parameters:
list - non-null; the list which was notified
item - null-ok; the item that was updated
index - >= 0; the index that the item is at

onItemAdded

public final void onItemAdded(ActiveList list,
                              Object item,
                              int index)
Description copied from interface: ActiveList.Delegate
This method is called whenever an item is added to an ActiveList instance.

Specified by:
onItemAdded in interface ActiveList.Delegate
Parameters:
list - non-null; the list which was modified
item - null-ok; the item that was added
index - >= 0; the index that the item was added (inserted) at

onRangeAdded

public final void onRangeAdded(ActiveList list,
                               Object[] items,
                               int start)
Description copied from interface: ActiveList.Delegate
This method is called whenever a contiguous range of items is added to an ActiveList instance.

Specified by:
onRangeAdded in interface ActiveList.Delegate
Parameters:
list - non-null; the list which was modified
items - non-null; array containing the items that were added
start - >= 0; the start index that the range was added (inserted) at

onItemRemoved

public final void onItemRemoved(ActiveList list,
                                Object item,
                                int index)
Description copied from interface: ActiveList.Delegate
This method is called whenever an individual item is removed from an ActiveList instance. For example, StdActiveList.removeItem(java.lang.Object) or and StdActiveList.removeItemAt(int) are two concrete methods that remove individual items from an instance.

Specified by:
onItemRemoved in interface ActiveList.Delegate
Parameters:
list - non-null; the list which was modified
item - null-ok; the item that was removed
index - >= 0; the index that the item was removed from

onRangeRemoved

public final void onRangeRemoved(ActiveList list,
                                 Object[] items,
                                 int start)
Description copied from interface: ActiveList.Delegate
This method is called whenever a range of items is removed from an ActiveList instance. For example, StdActiveList.removeRange(int, int) and StdActiveList.removeAllItems() are two concrete methods that remove ranges of items from an instance.

Specified by:
onRangeRemoved in interface ActiveList.Delegate
Parameters:
list - non-null; the list which was modified
items - non-null; array containing the removed items
start - >= 0; the start index that the items were removed from

onItemsReordered

public final void onItemsReordered(ActiveList list)
Description copied from interface: ActiveList.Delegate
This method is called whenever items get reordered in an ActiveList instance. For example, StdActiveList.sort(java.util.Comparator) is a concrete method that reorders the items of an instance.

Specified by:
onItemsReordered in interface ActiveList.Delegate
Parameters:
list - non-null; the list which was modified

accept

protected void accept(Object obj)
Do the operation for a delegate.

Overrides:
accept in class SimpleWeakList
Parameters:
obj - non-null; the delegate