peer2me.group
Class Group

java.lang.Object
  extended by peer2me.group.Group

public class Group
extends java.lang.Object

A simple class for storing information about a group and its nodes. Can contain several instances of Node.

Author:
Tommy Bjoernsgaard

Constructor Summary
Group(java.lang.String name)
          Creates a new instance of Group.
Group(java.lang.String name, Node[] nodes)
          Creates a new instance of Group with a name and existing nodes
 
Method Summary
 void addNode(Node node)
          Adds a Node the group
 int getIndexOfNode(Node node)
          Returns the index of a given Node.
 java.lang.String getName()
          Gets the name of the group
 Node getNode(java.lang.String address)
          Gets a Node with the specified address
 Node getNodeAt(int index)
          Gets a Node at det specified index
 Node[] getNodes()
          Gets an array of Node in the group
 int getNumberOfNodes()
          Returns the number of nodes in the group.
 void removeAllNodes()
          Removes all nodes from the group
 void removeNode(Node node)
          Removes the specified Node
 void removeNode(java.lang.String address)
          Removes a Node with the given address
 void removeNodeAt(int index)
          Removes a Node at the specified index
 void setName(java.lang.String name)
          Alters the name of the group
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Group

public Group(java.lang.String name)
Creates a new instance of Group.

Parameters:
name - the name of the group

Group

public Group(java.lang.String name,
             Node[] nodes)
Creates a new instance of Group with a name and existing nodes

Parameters:
name - the name of the group
nodes - an array of nodes to put in the group
Method Detail

addNode

public void addNode(Node node)
Adds a Node the group

Parameters:
node - The node to add

getNodes

public Node[] getNodes()
Gets an array of Node in the group

Returns:
an array of Node with all the nodes in the group

getNodeAt

public Node getNodeAt(int index)
               throws NodeNotFoundException
Gets a Node at det specified index

Parameters:
index - inded of the node
Returns:
the node at the specified index
Throws:
NodeNotFoundException

getNode

public Node getNode(java.lang.String address)
             throws NodeNotFoundException
Gets a Node with the specified address

Parameters:
address - the address of the node
Returns:
the node with specified address
Throws:
NodeNotFoundException

getIndexOfNode

public int getIndexOfNode(Node node)
Returns the index of a given Node. Useful when finding out if a node exists in this group

Parameters:
node - the node to find the index of
Returns:
index of the node give as parameter

getNumberOfNodes

public int getNumberOfNodes()
Returns the number of nodes in the group.

Returns:
An integer representing the number of nodes

removeNodeAt

public void removeNodeAt(int index)
                  throws NodeNotFoundException
Removes a Node at the specified index

Parameters:
index - index of the node
Throws:
NodeNotFoundException

removeNode

public void removeNode(java.lang.String address)
                throws NodeNotFoundException
Removes a Node with the given address

Parameters:
address - the address of the node
Throws:
NodeNotFoundException

removeNode

public void removeNode(Node node)
Removes the specified Node

Parameters:
node - the node to remove

removeAllNodes

public void removeAllNodes()
Removes all nodes from the group


getName

public java.lang.String getName()
Gets the name of the group

Returns:
name of the group

setName

public void setName(java.lang.String name)
Alters the name of the group

Parameters:
name - the new name