gumbo.util
Class AbstractGroup

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--gumbo.util.AbstractGroup
All Implemented Interfaces:
java.util.Collection, Group, java.io.Serializable

public class AbstractGroup
extends java.util.AbstractCollection
implements java.io.Serializable, Group

An abstract implementation of the Group interface. Intended as a lightweight proxy for a group's store, with lazy build of the store and this object's immutable views. Uses the decorator pattern to wrap an external target store or, if none, uses lazy build for an internal one.

Although collections have become efficient as regards memory and new object usage, this class goes farther by acting as a proxy for the target collection itself, with the lazy build target remaining null as long as it is empty or not being viewed. As such, all accessors test for isEmpty() before creating the backing store.

Version:
$Revision: 1.4 $
Author:
Jon Barrilleaux (jonb@jmbaai.com) of JMB and Associates Inc.
See Also:
Serialized Form

Constructor Summary
AbstractGroup()
          Constructs an instance, with an empty lazy build store (see newGroupStore()).
AbstractGroup(java.util.Collection init)
          Constructs an instance, with an initialized store (see newGroupStore()).
AbstractGroup(java.util.Collection init, java.util.Collection target)
          Constructs an instance, with a wrapped and initialized store.
AbstractGroup(java.lang.Object[] init)
          Constructs an instance, with an initialized store (see newGroupStore()).
 
Method Summary
 void add(int index, java.lang.Object member)
          Similar to List.add(int, Object), but functionally equivalent to Collection.add(Object) if index is <0.
 boolean add(java.lang.Object member)
           
 boolean addAll(java.util.Collection members)
           
 void addAll(int index, java.util.Collection members)
          Similar to List.addAll(int, Collection), but functionally equivalent to Collection.addAll(Collection) if index is <0.
 boolean contains(java.lang.Object member)
           
 boolean containsAll(java.util.Collection members)
           
 boolean containsAny(java.util.Collection members)
          Returns true if this group contains any of the specified members.
 boolean equals(java.lang.Object obj)
           
 Group getGroup()
          Gets an immutable view of this group.
protected  java.util.Collection getGroupStore()
          Called by the system to access the mutable backing store.
 java.util.List getList()
          Gets a singleton immutable view of the group store as a list, which is useful for testing equality with another list.
 java.util.Set getSet()
          Gets a singleton immutable view of the group store as a set, which is useful for testing equality with another set.
 int hashCode()
           
 java.util.Iterator iterator()
           
protected  java.util.Collection newGroupStore()
          Called by the system when it needs to lazily build the group backing store.
 boolean remove(java.lang.Object member)
           
 boolean removeAll(java.util.Collection members)
           
 boolean retainAll(java.util.Collection members)
           
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class java.util.AbstractCollection
clear, isEmpty, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
clear, isEmpty, toArray, toArray
 

Constructor Detail

AbstractGroup

public AbstractGroup()
Constructs an instance, with an empty lazy build store (see newGroupStore()).


AbstractGroup

public AbstractGroup(java.util.Collection init)
Constructs an instance, with an initialized store (see newGroupStore()).

Parameters:
init - The initial members (Object). None if null.

AbstractGroup

public AbstractGroup(java.lang.Object[] init)
Constructs an instance, with an initialized store (see newGroupStore()).

Parameters:
init - The initial members. Never null.

AbstractGroup

public AbstractGroup(java.util.Collection init,
                     java.util.Collection target)
Constructs an instance, with a wrapped and initialized store. Master constructor.

Parameters:
init - The initial members (Object). None if null.
target - The target group store being wrapped. If null, defaults to the lazy build target (see newGroupStore()). If init is non-null, any contents will be lost.
Method Detail

newGroupStore

protected java.util.Collection newGroupStore()
Called by the system when it needs to lazily build the group backing store. Defaults to a SetList. Override as needed with a different collection type. Master mutator.

Returns:
A new empty store. Never null.

getGroupStore

protected java.util.Collection getGroupStore()
Called by the system to access the mutable backing store. As needed, calls newGroupStore() to lazily build the store. Master accessor.

Returns:
The group store. Never null.
Throws:
java.lang.IllegalStateException - New group store is null.

add

public void add(int index,
                java.lang.Object member)
Description copied from interface: Group
Similar to List.add(int, Object), but functionally equivalent to Collection.add(Object) if index is <0. Can be safely called with index <0 even if the group store is not a List. Some stores (such as SetList) may throw an exception when attempting to add a duplicate member.

Specified by:
add in interface Group
Parameters:
index - Index of the added member. If <0 the member is added to the end of the list.
member - The member to be added, which may be null.

addAll

public void addAll(int index,
                   java.util.Collection members)
Description copied from interface: Group
Similar to List.addAll(int, Collection), but functionally equivalent to Collection.addAll(Collection) if index is <0. Can be safely called with index <0 even if the group store is not a List. Some stores (such as SetList) may throw an exception when attempting to add a duplicate member.

Specified by:
addAll in interface Group
Parameters:
index - Index of the first added member. If <0 the members are added to the end of the list.
members - The members (Object) to be added, which may be null. Never null.

containsAny

public boolean containsAny(java.util.Collection members)
Description copied from interface: Group
Returns true if this group contains any of the specified members.

Specified by:
containsAny in interface Group
Parameters:
members - The members, which may be null. Never null.
Returns:
The result.

getGroup

public Group getGroup()
Description copied from interface: Group
Gets an immutable view of this group. When possible, use other accessors, such as isEmpty(), instead of this view, which minimizes lazy builds.

Specified by:
getGroup in interface Group
Returns:
The view (Object). Never null.

getSet

public java.util.Set getSet()
Description copied from interface: Group
Gets a singleton immutable view of the group store as a set, which is useful for testing equality with another set. When possible, use other accessors, such as isEmpty(), instead of this view, which minimizes lazy builds.

Specified by:
getSet in interface Group
Returns:
The view (Object). Never null.

getList

public java.util.List getList()
Description copied from interface: Group
Gets a singleton immutable view of the group store as a list, which is useful for testing equality with another list. If the group store is a SetList, the view will be castable to SetList. When possible, use other accessors, such as isEmpty(), instead of this view, which minimizes lazy builds.

Specified by:
getList in interface Group
Returns:
The view (Object). Never null.

add

public boolean add(java.lang.Object member)
Specified by:
add in interface java.util.Collection
Overrides:
add in class java.util.AbstractCollection

addAll

public boolean addAll(java.util.Collection members)
Specified by:
addAll in interface java.util.Collection
Overrides:
addAll in class java.util.AbstractCollection

remove

public boolean remove(java.lang.Object member)
Specified by:
remove in interface java.util.Collection
Overrides:
remove in class java.util.AbstractCollection

removeAll

public boolean removeAll(java.util.Collection members)
Specified by:
removeAll in interface java.util.Collection
Overrides:
removeAll in class java.util.AbstractCollection

retainAll

public boolean retainAll(java.util.Collection members)
Specified by:
retainAll in interface java.util.Collection
Overrides:
retainAll in class java.util.AbstractCollection

contains

public boolean contains(java.lang.Object member)
Specified by:
contains in interface java.util.Collection
Overrides:
contains in class java.util.AbstractCollection

containsAll

public boolean containsAll(java.util.Collection members)
Specified by:
containsAll in interface java.util.Collection
Overrides:
containsAll in class java.util.AbstractCollection

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in class java.util.AbstractCollection

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in class java.util.AbstractCollection

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection

equals

public boolean equals(java.lang.Object obj)
Specified by:
equals in interface java.util.Collection
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection
Overrides:
hashCode in class java.lang.Object