org.jogre.common
Class User

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

public class User
extends Observable
implements ITransmittable

Transmittable user data object. Contains the username, score, number of wins/loses and draws.

Version:
Alpha 0.2.3
Author:
Bob Marks

Field Summary
protected  int draws
          Score rating of User.
protected  int loses
          Score rating of User.
protected  int rating
          Score rating of User.
protected  int streak
          Score rating of User.
protected  String username
          Username of User.
protected  int wins
          Score rating of User.
 
Constructor Summary
User(String username, int rating, int wins, int loses, int draws, int streak)
          User constructor which takes a username, rating, number of wins, loses, draws and a user streak.
User(XMLElement message)
          Constructor which creates a User object from the flatten () method of another User object.
 
Method Summary
 boolean equals(Object obj)
          Customer equals method to compare User objects
 XMLElement flatten()
          Flatten the User object for transmission.
 int getDraws()
          Return the number of draws a user has had.
 int getGamesPlayed()
          Return the number of games this player has played.
 int getLosses()
          Return the number of losses a user has had.
 int getRating()
          Returns the rating of this particular user (currently not implemented).
 int getStreak()
          Return the user streak.
 String getUsername()
          Return the username of this user.
 int getWins()
          Return the number of wins a user has had.
 boolean isProvisional()
          Return true if a user is still provisional.
 void update(int resultType, int newRating)
          Update a user depending on a result type and their new rating.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

username

protected String username
Username of User.


rating

protected int rating
Score rating of User.


wins

protected int wins
Score rating of User.


draws

protected int draws
Score rating of User.


loses

protected int loses
Score rating of User.


streak

protected int streak
Score rating of User.

Constructor Detail

User

public User(String username,
            int rating,
            int wins,
            int loses,
            int draws,
            int streak)
User constructor which takes a username, rating, number of wins, loses, draws and a user streak.

Parameters:
username - Username of user.
rating - User rating.
wins - Number of user wins.
loses - Number of users loses.
draws - Number of user draws.
streak - Streak of user.

User

public User(XMLElement message)
     throws TransmissionException
Constructor which creates a User object from the flatten () method of another User object.

Parameters:
message - XMLElement communication object.
Throws:
TransmissionException - Thrown if there is a problem in transmission.
Method Detail

getUsername

public String getUsername()
Return the username of this user.

Returns:
username Username as a String.

getRating

public int getRating()
Returns the rating of this particular user (currently not implemented).

Returns:
rating Rating of user (int)

getDraws

public int getDraws()
Return the number of draws a user has had.

Returns:
Number of draws.

getLosses

public int getLosses()
Return the number of losses a user has had.

Returns:
Number of losses.

getWins

public int getWins()
Return the number of wins a user has had.

Returns:
Number of wins.

getStreak

public int getStreak()
Return the user streak. For example, if a user has won 3 games in a row - this is 3. If he has lost 4 then its -4. If he won 2 and then lost 1 it is -1.

Returns:
Streak of user.

getGamesPlayed

public int getGamesPlayed()
Return the number of games this player has played.

Returns:
Total number of games played (wins + loses + draws).

isProvisional

public boolean isProvisional()
Return true if a user is still provisional.

Returns:
True if user is still in provisional.

update

public void update(int resultType,
                   int newRating)
Update a user depending on a result type and their new rating.

Parameters:
resultType - Result type - e.g. win, lose or draw
newRating - New rating

flatten

public XMLElement flatten()
Flatten the User object for transmission.

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

equals

public boolean equals(Object obj)
Customer equals method to compare User objects

See Also:
Object.equals(java.lang.Object)