org.jogre.common
Class TableList

java.lang.Object
  extended byjava.util.Observable
      extended byorg.jogre.common.TableList
All Implemented Interfaces:
ITransmittable

public class TableList
extends Observable
implements ITransmittable

Contains a HashMap of all the Table objects currently in play. This class also implements the ITransmittable interface so this object can be transferred across the network.

Version:
Alpha 0.2.1
Author:
Bob Marks

Field Summary
protected  HashMap tablelist
          HashMap containing a number of Table objects.
static String XML_NAME
          Name of the XMLElement.
 
Constructor Summary
TableList()
          Default constructor which sets up a brand new TableList object with no Tables in its HashMap.
TableList(XMLElement message)
          Constructor which recreates a Table object using a String from the ITransmittable.flatten() method from another TableList object.
 
Method Summary
 void addTable(String username, boolean isPublic, JogrePropertyHash properties)
          Add a new Table object to the HashMap.
 Integer computeNewTableNum()
          Computes a new table number.
 XMLElement flatten()
          Flatten the current list of logged on users.
 Table getTable(int tableNum)
          Return a Table object from a specified table number.
 int[] getTablesNumbers()
          Returns a list of all the table numbers.
 void removePlayer(int tableNum, String player)
          Remove a player from a table.
 void removeTable(int tableNum)
          Remove table from the list.
 void removeUserFromTables(String player)
          Remove a user from tables.
 int size()
          Return the size of the table list.
 void updateTable(int tableNum, Table table)
          Update a table in the table list.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_NAME

public static final String XML_NAME
Name of the XMLElement.

See Also:
Constant Field Values

tablelist

protected HashMap tablelist
HashMap containing a number of Table objects. They key is an Integer object of the table number.

Constructor Detail

TableList

public TableList()
Default constructor which sets up a brand new TableList object with no Tables in its HashMap.


TableList

public TableList(XMLElement message)
          throws TransmissionException
Constructor which recreates a Table object using a String from the ITransmittable.flatten() method from another TableList object.

Parameters:
message - String representation of a TableList object
Throws:
TransmissionException
Method Detail

addTable

public void addTable(String username,
                     boolean isPublic,
                     JogrePropertyHash properties)
Add a new Table object to the HashMap. The Table object is created using the parameters username, isPublic and a computed table number which is generated using the computeNewTableNum() method. This Table object is then stored in a HashMap with this computed table number (Integer) as its key.

Parameters:
username -
isPublic -

removeTable

public void removeTable(int tableNum)
Remove table from the list. This is usually called when all the users leave a particular table for example.

Parameters:
tableNum - Number of the table to be removed.

removePlayer

public void removePlayer(int tableNum,
                         String player)
Remove a player from a table. If the player is the last player to leave the table OR if this player is the owner of the table then the table will also be removed from the HashMap.

Parameters:
tableNum - Table number.
player -

removeUserFromTables

public void removeUserFromTables(String player)
Remove a user from tables.

Parameters:
player -

getTable

public Table getTable(int tableNum)
Return a Table object from a specified table number.

Parameters:
tableNum - Table number.
Returns:
Table object if exists.

getTablesNumbers

public int[] getTablesNumbers()
Returns a list of all the table numbers.

Returns:
Array of integer table numbers.

updateTable

public void updateTable(int tableNum,
                        Table table)
Update a table in the table list.

Parameters:
tableNum -
table -

size

public int size()
Return the size of the table list.

Returns:
Number of Table objects in TableList.

computeNewTableNum

public Integer computeNewTableNum()
Computes a new table number.

Returns:
Unique table number.

flatten

public XMLElement flatten()
Flatten the current list of logged on users.

Specified by:
flatten in interface ITransmittable
Returns:
XML version of the state of an object which can be constructed again.
See Also:
ITransmittable.flatten()