net.beadsproject.beads.core
Class BeadArray

java.lang.Object
  extended by net.beadsproject.beads.core.Bead
      extended by net.beadsproject.beads.core.BeadArray

public class BeadArray
extends Bead

BeadArray represents an array of Beads (and is itself a subclass of Bead). Its purpose is to forward messages to its array members. A BeadArray detects whether or not its members are deleted, and removes them if they are. For this reason it should be used in any situations where a Bead needs to be automatically disposed of. Note, however, that a BeadArray does not forward Bead.kill(), Bead.start() and Bead.pause(boolean) messages to its component Beads unless told to do so by setting setForwardKillCommand(boolean) and setForwardPauseCommand(boolean) respectively.

Author:
ollie

Constructor Summary
BeadArray()
          Creates an empty BeadArray.
 
Method Summary
 void add(Bead bead)
          Adds a new Bead to the list of receivers.
 void clear()
          Clears the list of receivers.
 BeadArray clone()
          Creates a shallow copy of itself.
 boolean doesForwardKillCommand()
          Checks if this BeadArray forwards kill commands.
 boolean doesForwardPauseCommand()
          Checks if this BeadArray forwards pause commands.
 Bead get(int i)
          Gets the ith Bead from the list of receivers.
 java.util.ArrayList<Bead> getBeads()
          Gets the contents of this BeadArrays as an ArrayList of Beads.
 void kill()
          Stops this Bead, and flags it as deleted.
 void messageReceived(Bead message)
          Forwards incoming message to all receivers.
 void pause(boolean paused)
          Toggle the paused state of the Bead.
 void remove(Bead bead)
          Removes a Bead from the list of receivers.
 void setForwardKillCommand(boolean forwardKillCommand)
          Determines whether or not this BeadArray forwards kill commands.
 void setForwardPauseCommand(boolean forwardPauseCommand)
          Determines whether or not this BeadArray forwards pause commands.
 int size()
          Gets the size of the list of receivers.
 void start()
          Shortcut for pause(false).
 
Methods inherited from class net.beadsproject.beads.core.Bead
getKillListener, getName, isDeleted, isPaused, message, setKillListener, setName, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BeadArray

public BeadArray()
Creates an empty BeadArray.

Method Detail

add

public void add(Bead bead)
Adds a new Bead to the list of receivers.

Parameters:
bead - Bead to add.

remove

public void remove(Bead bead)
Removes a Bead from the list of receivers.

Parameters:
bead - Bead to remove.

get

public Bead get(int i)
Gets the ith Bead from the list of receivers.

Parameters:
i - index of Bead to retrieve.
Returns:
the Bead at the ith index.

clear

public void clear()
Clears the list of receivers.


size

public int size()
Gets the size of the list of receivers.

Returns:
size of list.

getBeads

public java.util.ArrayList<Bead> getBeads()
Gets the contents of this BeadArrays as an ArrayList of Beads.

Returns:
the beads.

messageReceived

public void messageReceived(Bead message)
Forwards incoming message to all receivers.

Overrides:
messageReceived in class Bead
Parameters:
message - incoming message.

clone

public BeadArray clone()
Creates a shallow copy of itself.

Overrides:
clone in class java.lang.Object
Returns:
shallow copy of this Bead.

doesForwardKillCommand

public boolean doesForwardKillCommand()
Checks if this BeadArray forwards kill commands.

Returns:
true if this BeadArray forwards kill commands.

setForwardKillCommand

public void setForwardKillCommand(boolean forwardKillCommand)
Determines whether or not this BeadArray forwards kill commands.

Parameters:
forwardKillCommand - true if this BeadArray forwards kill commands.

doesForwardPauseCommand

public boolean doesForwardPauseCommand()
Checks if this BeadArray forwards pause commands.

Returns:
true if this BeadArray forwards pause commands.

setForwardPauseCommand

public void setForwardPauseCommand(boolean forwardPauseCommand)
Determines whether or not this BeadArray forwards pause commands.

Parameters:
forwardPauseCommand - true if this BeadArray forwards pause commands.

kill

public void kill()
Description copied from class: Bead
Stops this Bead, and flags it as deleted. This means that the Bead will automatically be removed from any BeadArrays.

Overrides:
kill in class Bead

pause

public void pause(boolean paused)
Description copied from class: Bead
Toggle the paused state of the Bead.

Overrides:
pause in class Bead
Parameters:
paused - true to pause Bead.

start

public void start()
Description copied from class: Bead
Shortcut for pause(false).

Overrides:
start in class Bead