gumbo.interact
Class InteractorGroup

java.lang.Object
  |
  +--gumbo.interact.InteractorGroup
All Implemented Interfaces:
Interactor

public class InteractorGroup
extends java.lang.Object
implements Interactor

An interactor representing a group of interactors, in a composite pattern. An interactor group propagates its interaction state to its member interactors, assuring consistency of interaction state throughout the group. The interactors in an interactor group must have update policies that are mutually compatible with that of this group's interactor state.

An interactor can be a member of none or more groups. As such, interactor groups can serve as different interaction "roles" for the same interactor. For example, one interactor group can serve the role of "self", which includes all interactors representing a given data model in different views. Another interactor group can serve the role of "command selection", which includes all multi-selected command target interactors. And, another interactor group can serve the role of "aspect selection", which includes all interactors associated with the members of an aspect model. When used to support roles, the interactor group should use partial state updates.

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

Constructor Summary
InteractorGroup()
          Creates an instance, with a default InteractorState and partial state propagation.
InteractorGroup(InteractorState state, boolean partial)
          Creates an instance, with a new interactor state as this group's state.
 
Method Summary
 boolean addMember(Interactor member, boolean sync)
          Adds an interactor as a member of this group.
 void clearMembers(boolean desync)
          Convenience method that removes all members from this group.
 boolean equals(java.lang.Object obj)
           
 InteractorGroup getInteractorGroup()
          Gets a singleton immutable view of this object with the same identity (hashCode(), equals()) as this object.
 InteractorState getInteractorState()
          Gets the interactor state value for this interactor.
 java.util.Set getMembers()
          Returns an immutable view of the members of this group.
 boolean isPartialUpdate()
           
 boolean removeMember(Interactor member, boolean desync)
          Removes an interactor as a member from this group.
 void syncMembers()
          Syncs the members of this group with this group's current state value (full or partial).
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InteractorGroup

public InteractorGroup()
Creates an instance, with a default InteractorState and partial state propagation.


InteractorGroup

public InteractorGroup(InteractorState state,
                       boolean partial)
Creates an instance, with a new interactor state as this group's state. The initial state and state policy will be that of the new interactor state.

Parameters:
state - New interactor state. If null, a default InteractorState is used (see InteractorState).
partial - If true, state updates are propagated to members as partial "masked changes" (see StateSet.change(StateSet)); otherwise, the full state is propagated. This does not affect state resets, which always propagate the full state. Unless this group has exclusive control over its members, should be true (partial state update).
Method Detail

isPartialUpdate

public boolean isPartialUpdate()

getInteractorGroup

public InteractorGroup getInteractorGroup()
Gets a singleton immutable view of this object with the same identity (hashCode(), equals()) as this object.

Returns:
The view. Never null.

addMember

public boolean addMember(Interactor member,
                         boolean sync)
Adds an interactor as a member of this group. Member order is undefined.

Parameters:
member - Member to be added. Silently ignores null and duplicate members.
sync - If true, the new member's state is synced (full or partial) with that of this group.
Returns:
True if the group actually changed.
Throws:
java.lang.IllegalArgumentException - Can't add this group to itself.

removeMember

public boolean removeMember(Interactor member,
                            boolean desync)
Removes an interactor as a member from this group. If sync is true, the old member's state is synced with the absence of this group's state (full or partial state removed).

Parameters:
member - Member to be removed. Silently ignores null and missing members.
desync - If true, the old member's state is desynced by removing this group's state (full or partial).
Returns:
True if the group actually changed.

clearMembers

public void clearMembers(boolean desync)
Convenience method that removes all members from this group.

Parameters:
desync - If true, the old member's state is desynced by removing this group's state (full or partial).

getMembers

public java.util.Set getMembers()
Returns an immutable view of the members of this group. Members are un-ordered.

Returns:
Group members (Interactor). Never null.

syncMembers

public void syncMembers()
Syncs the members of this group with this group's current state value (full or partial).


getInteractorState

public InteractorState getInteractorState()
Description copied from interface: Interactor
Gets the interactor state value for this interactor.

Specified by:
getInteractorState in interface Interactor
Returns:
Reference to the interactor state. Never null.

toString

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

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object