hermes
Class GenericGroup<A extends HObject,B extends java.util.Collection<A>>

java.lang.Object
  extended by hermes.GenericGroup<A,B>
Type Parameters:
A - the type of the objects in the group
B - the type of underlying collection used
All Implemented Interfaces:
KeySubscriber, MouseSubscriber, MouseWheelSubscriber, OscSubscriber
Direct Known Subclasses:
Group

public class GenericGroup<A extends HObject,B extends java.util.Collection<A>>
extends java.lang.Object
implements KeySubscriber, MouseSubscriber, MouseWheelSubscriber, OscSubscriber

Groups together generic HObjects using the specified collection that share common attributes and interact with another group of HObjects.

Like Beings, GenericGroups can have their own update methods.

The primary purpose of grouping is for use in interactions. However, GenericGroups can also be used to store data about or provide access to the contained objects. For example, groups can keep track of the ages of the objects it contains and direct messages to either the oldest or the newest object.

See World for more details on registering interactions or Updates.

See Also:
Interactor, HObject

Field Summary
protected  World _world
           
 
Constructor Summary
GenericGroup(B objects, World world)
          Instantiates a group storing HObjects in the given collection.
 
Method Summary
 A add(A being)
          Adds a being to the group at the end of the next update loop.
 void addAll(GenericGroup<A,?> group)
          Adds the contents of another group to this group.
 void clear()
          Clears everything from the group at the end of the update.
 void destroy()
          Deletes everything in the group from the world at the end of the update.
 B getObjects()
          Returns the underlying collection containing all objects in the group.
 World getWorld()
           
 boolean hasNeedsMoreSamples()
          Used internally.
 java.util.Iterator<A> iterator()
          An iterator over the underlying collection.
 void receive(KeyMessage m)
          Override if you want your group to handle Key messages
 void receive(MouseMessage m)
          Override if you want your group to handle Mouse messages
 void receive(MouseWheelMessage m)
          Override if you want your group to handle Mouse Wheel messages
 void receive(OscMessage m)
          Override if you want your group to handle OSC messages
 A remove(A object)
          Removes an object from the group at the end of the next update loop.
 void removeAll(GenericGroup<A,?> group)
          Removes the contents of a group from this group.
 void setWorld(World world)
           
 int size()
           
 void update()
          Performs an update on the group.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_world

protected World _world
Constructor Detail

GenericGroup

public GenericGroup(B objects,
                    World world)
Instantiates a group storing HObjects in the given collection.

Parameters:
objects - the collection objects will be stored in
world - the world where the group will be used
Method Detail

getObjects

public B getObjects()
Returns the underlying collection containing all objects in the group. WARNING -- DO NOT ADD TO OR REMOVE FROM THIS COLLECTION DIRECTLY

Returns:
the data structure containing all objects in the group

iterator

public java.util.Iterator<A> iterator()
An iterator over the underlying collection. WARNING -- DO NOT REMOVE BEINGS USING Iterator.remove()

Returns:
an iterator over all elements in the group

update

public void update()
Performs an update on the group. Override to use.


add

public A add(A being)
Adds a being to the group at the end of the next update loop.

Parameters:
being - the being to add
Returns:
the added object

remove

public A remove(A object)
Removes an object from the group at the end of the next update loop.

Parameters:
object - the object to remove
Returns:
the removed object

addAll

public void addAll(GenericGroup<A,?> group)
Adds the contents of another group to this group. Will always be O(n) regardless of the underlying collection.

Parameters:
group - the objects to add

removeAll

public void removeAll(GenericGroup<A,?> group)
Removes the contents of a group from this group.

Parameters:
group - the objects to remove

clear

public void clear()
Clears everything from the group at the end of the update. This will always be O(n), regardless of the underlying collection.


destroy

public void destroy()
Deletes everything in the group from the world at the end of the update. Note: this means the group and its beings are totally destroyed! They will be removed from any other groups they are in. This will always be O(n), regardless of the underlying collection.


size

public int size()
Returns:
the number of beings contained by the group

setWorld

public void setWorld(World world)
Parameters:
world - the world the group should be contained by

getWorld

public World getWorld()
Returns:
the world currently containing the group

hasNeedsMoreSamples

public boolean hasNeedsMoreSamples()
Used internally. Whether the group contains objects that need more samples on this update.

Returns:
true if objects within the group need more samples, false if no objects do

receive

public void receive(KeyMessage m)
Override if you want your group to handle Key messages

Specified by:
receive in interface KeySubscriber
Parameters:
m - the message sent by the PostOffice

receive

public void receive(MouseMessage m)
Override if you want your group to handle Mouse messages

Specified by:
receive in interface MouseSubscriber
Parameters:
m - the message sent by the PostOffice

receive

public void receive(MouseWheelMessage m)
Override if you want your group to handle Mouse Wheel messages

Specified by:
receive in interface MouseWheelSubscriber
Parameters:
m - the message sent by the PostOffice

receive

public void receive(OscMessage m)
Override if you want your group to handle OSC messages

Specified by:
receive in interface OscSubscriber
Parameters:
m - the message sent by the PostOffice