com.tootsville
Class UserList

java.lang.Object
  extended by org.starhope.appius.sql.SQLPeerDatum
      extended by com.tootsville.UserList
All Implemented Interfaces:
Serializable, Comparable<Object>, UserList

public class UserList
extends SQLPeerDatum
implements UserList

Generic class that handles both buddy lists and ignore lists, depending upon its mood. Unlike most of my stuff, you can actually use the constructor safely, here.

Author:
brpocock@star-hope.org
See Also:
Serialized Form

Field Summary
(package private)  AbstractZone activeZone
          The Zone in which the owner of this list is active
private  int myUserID
          WRITEME
private static long serialVersionUID
          Java serialisations unique ID
private  String tableName
          WRITEME
(package private)  HashMap<Integer,String> theRealList
          WRITEME
 
Constructor Summary
UserList(AbstractUser myGuy, boolean buddyTrueBlockFalse)
           
UserList(UserRecord myGuy, boolean buddyTrueIgnoreFalse)
          WRITEME: Document this constructor brpocock@star-hope.org
 
Method Summary
 boolean addUser(AbstractUser other)
          Add a user to this list
 User[] asArrayOfUsers()
          Deprecated. 
 Map<Integer,String> asMap()
          Get a map copy of the buddy list with keys as user ID's and values as user names.
 Set<String> asNames()
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void changed()
          Indicate that some of the contents of this datum have changed, and that the database and/or object caches may need to be updated.
 void flush()
          This is an overriding method.
static String getBuddyApprovalCookie(AbstractUser requester, AbstractUser requestee)
          Generate an opaque cookie which can only be produced by the requester, and must be returned by the requestee in order to prove that a request has been made.
protected  String getCacheUniqueID()
          This is an overriding method.
private  void init(AbstractZone zone)
          WRITEME: document this method (brpocock@star-hope.org, Aug 31, 2009)
 boolean isOnList(AbstractUser u)
          WRITEME: document this method (brpocock@star-hope.org, Aug 31, 2009)
private  void readList()
          Read the user list from the database (XXX: contains SQL)
 boolean removeUser(AbstractUser other)
          Remove a user from this list (XXX: contains SQL)
protected  void set(ResultSet rs)
          This is an overriding method.
 int size()
           
 org.json.JSONObject toJSON(AbstractZone zone)
          Convert this list into a JSON form.
 
Methods inherited from class org.starhope.appius.sql.SQLPeerDatum
compareTo, findInCache, get, saveInCache, set, toJSON
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Java serialisations unique ID

See Also:
Constant Field Values

activeZone

transient AbstractZone activeZone
The Zone in which the owner of this list is active


myUserID

private int myUserID
WRITEME


tableName

private final String tableName
WRITEME


theRealList

HashMap<Integer,String> theRealList
WRITEME

Constructor Detail

UserList

public UserList(AbstractUser myGuy,
                boolean buddyTrueBlockFalse)
Parameters:
myGuy - The user whose buddy list or ignore list is being instantiated
buddyTrueBlockFalse - true, for buddy list; false, for ignore list.

UserList

public UserList(UserRecord myGuy,
                boolean buddyTrueIgnoreFalse)
WRITEME: Document this constructor brpocock@star-hope.org

Parameters:
myGuy - WRITEME
buddyTrueIgnoreFalse - WRITEME
Method Detail

getBuddyApprovalCookie

public static String getBuddyApprovalCookie(AbstractUser requester,
                                            AbstractUser requestee)
Generate an opaque cookie which can only be produced by the requester, and must be returned by the requestee in order to prove that a request has been made. Note that a buddy list request will (by design) be invalid after either user changes their user name.

Parameters:
requester - user placing the buddy request
requestee - user being requested as a buddy
Returns:
the cookie

addUser

public boolean addUser(AbstractUser other)
Add a user to this list

Specified by:
addUser in interface UserList
Parameters:
other - the user to be added
Returns:
true if the user was null (no-op) or was added successfully; false if the user was already on the list
See Also:
UserList.addUser(AbstractUser)

asArrayOfUsers

@Deprecated
public User[] asArrayOfUsers()
Deprecated. 

Returns an extremely expensive list of users.

Returns:
all users on the given list as User objects. Very expensive inquiry.

asMap

public Map<Integer,String> asMap()
Description copied from interface: UserList
Get a map copy of the buddy list with keys as user ID's and values as user names.

Specified by:
asMap in interface UserList
Returns:
get a copy of the user list in a Map form (ID to user name)
See Also:
UserList.asMap()

asNames

public Set<String> asNames()
Description copied from interface: UserList
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Specified by:
asNames in interface UserList
Returns:
WRITEME
See Also:
UserList.asNames()

changed

public void changed()
Description copied from class: SQLPeerDatum
Indicate that some of the contents of this datum have changed, and that the database and/or object caches may need to be updated.

Specified by:
changed in interface UserList
Overrides:
changed in class SQLPeerDatum
See Also:
UserList.changed()

flush

public void flush()
Description copied from interface: UserList
This is an overriding method.

Specified by:
flush in interface UserList
Specified by:
flush in class SQLPeerDatum
See Also:
UserList.flush()

getCacheUniqueID

protected String getCacheUniqueID()
This is an overriding method.

Specified by:
getCacheUniqueID in class SQLPeerDatum
Returns:
The local (Stringified) version of an unique ID; usually the database ID column
See Also:
SQLPeerDatum.getCacheUniqueID()

init

private void init(AbstractZone zone)
WRITEME: document this method (brpocock@star-hope.org, Aug 31, 2009)

Parameters:
zone - WRITEME

isOnList

public boolean isOnList(AbstractUser u)
Description copied from interface: UserList
WRITEME: document this method (brpocock@star-hope.org, Aug 31, 2009)

Specified by:
isOnList in interface UserList
Parameters:
u - the user being checked
Returns:
true, if the user is on the list
See Also:
UserList.isOnList(AbstractUser)

readList

private void readList()
               throws SQLException
Read the user list from the database (XXX: contains SQL)

Throws:
SQLException - WRITEME

removeUser

public boolean removeUser(AbstractUser other)
Remove a user from this list (XXX: contains SQL)

Specified by:
removeUser in interface UserList
Parameters:
other - The other user to remove from this list
Returns:
true if the user has been removed from the list, or was null; false, if the user was non-null, but not on the list to begin with
See Also:
UserList.removeUser(AbstractUser)

set

protected void set(ResultSet rs)
            throws SQLException
This is an overriding method.

Specified by:
set in class SQLPeerDatum
Parameters:
rs - The result of an SQL query, with the cursor already pointed at the row describing this specific instance of the object.
Throws:
SQLException - if the database fails somehow
See Also:
SQLPeerDatum.set(java.sql.ResultSet)

size

public int size()
Specified by:
size in interface UserList
Returns:
the size of this list
See Also:
UserList.size()

toJSON

public org.json.JSONObject toJSON(AbstractZone zone)
                           throws org.json.JSONException
Convert this list into a JSON form. This takes a Zone reference so that the status of users (as to where they are located and whether they are online) can be reported in the list.

Specified by:
toJSON in interface UserList
Parameters:
zone - The zone for which the list's online status should be checked.
Returns:
the list in JSON form.
Throws:
org.json.JSONException - WRITEME
See Also:
UserList.toJSON(org.starhope.appius.types.AbstractZone)