social105
Class SocialDB

java.lang.Object
  extended bysocial105.SocialDB

public class SocialDB
extends java.lang.Object

A support class for ICS 105 projects on social networking. This provides basic support for building network structures relating people to each other, as well as supporting arbitrary properties that can be associated with people. It's basically a wrapper for a simple storage service.

To use this, start off by using SocialDB.getInstance() to get an instance of the SocialDB object. Next, identify yourself to the database using the login() method. This will keep your changes separate from other peoples. Probably, you should have one login per group, but you can use as many as you like. You can then use the other methods to record and lookup values in the database.


Constructor Summary
SocialDB()
          Constructor.
 
Method Summary
 void addFriend(java.lang.String person, java.lang.String friend)
          Add a new friend for a person.
 java.lang.String getAttributeValue(java.lang.String person, java.lang.String attribute)
          Look up the value of an attribute for a particular person.
static SocialDB getDB()
          Return a static instance of SocialDB, which encapsulates a connection to the database.
 java.util.List listAttributesOf(java.lang.String person)
          List all the attributes for a person.
 java.util.List listFriendsOf(java.lang.String person)
          Return a list of all the registered friends of a given person.
 java.util.List listPeople()
          Return a list of all the people known to the database.
 java.util.List listPeopleWithAttribute(java.lang.String attribute)
          Return a list of all the people who have a particular attribute defined, regardless of that attribute's value.
 java.util.List listPeopleWithAttributeValue(java.lang.String attribute, java.lang.String value)
          Return a list of all the people who have a particular attribute with a particular value.
 void login(java.lang.String newGroupName)
          Login to the database.
 void removeAttribute(java.lang.String person, java.lang.String attribute)
          Remove an attribute from a person.
 void removeFriend(java.lang.String person, java.lang.String friend)
          Remove a friend from a person.
 void setAttribute(java.lang.String person, java.lang.String attribute, java.lang.String value)
          Set an attribute and value for a person.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocialDB

public SocialDB()
Constructor. This is only used internally; the correct way to get a SocialDB object is to called SocialDB.getDB().

Method Detail

getDB

public static SocialDB getDB()
Return a static instance of SocialDB, which encapsulates a connection to the database. SocialDB is structured as a singleton, and so this is the right way to get a new SocialDB object.

Returns:
SocialDB instance of SocialDB for future calls.

login

public void login(java.lang.String newGroupName)
Login to the database.

This doesn't actually provide any access control; it only gives a name to associate with future actions, so as to partition one developer's or group's activities from others.


listPeople

public java.util.List listPeople()
Return a list of all the people known to the database. This is the basic set of people registered, not necessarily all their "friends." People are represented as strings (normally, email addresses, although there is no validation.)

Returns:
List a list of all the people registered.

listPeopleWithAttribute

public java.util.List listPeopleWithAttribute(java.lang.String attribute)
Return a list of all the people who have a particular attribute defined, regardless of that attribute's value.

Parameters:
attribute - String the name of an attribute to search on
Returns:
List a list of all the people with that attribute defined

listPeopleWithAttributeValue

public java.util.List listPeopleWithAttributeValue(java.lang.String attribute,
                                                   java.lang.String value)
Return a list of all the people who have a particular attribute with a particular value.

Parameters:
attribute - String the name of an attribute to search on
value - String the value of the attribute to search on
Returns:
List a list of all the people with that attribute and value

listFriendsOf

public java.util.List listFriendsOf(java.lang.String person)
Return a list of all the registered friends of a given person. If there are no friends registered, then the list is empty; if the person is not known, then null is returned.

Returns:
List list of Strings identifying friends

addFriend

public void addFriend(java.lang.String person,
                      java.lang.String friend)
Add a new friend for a person. The person need not have been known before.

Parameters:
person - String the person who has a friend

removeFriend

public void removeFriend(java.lang.String person,
                         java.lang.String friend)
Remove a friend from a person. If the friend was not previously listed, this is silently ignored.


listAttributesOf

public java.util.List listAttributesOf(java.lang.String person)
List all the attributes for a person. The list object that is returned lists all the attribute names; values need to be looked up separately via getAttributeValue().

Parameters:
person - String the person on whom attributes are defined
Returns:
List a list of attribute name strings

getAttributeValue

public java.lang.String getAttributeValue(java.lang.String person,
                                          java.lang.String attribute)
Look up the value of an attribute for a particular person. For instance, I might store the URL for everyone's homepage as a "homepage" attribute on the person; the value would be the URL. Names and values of attributes are Strings. If there is no attribute of this name listed for this person, return null.

Parameters:
person - String the person for whom this attribute is defined
attribute - String the name of the attribute
Returns:
String the value of the attribute for this person, if any

setAttribute

public void setAttribute(java.lang.String person,
                         java.lang.String attribute,
                         java.lang.String value)
Set an attribute and value for a person. This creates a new attribute if none of this name was defined for this person before; otherwise, it updates the value. For example, if I wanted to record the fact that the homepage for "jpd@ics.uci.edu" is http://www.dourish.com, then I might say: setAttribute("jpd@ics.uci.edu", "homepage", "http://www.dourish.com")

Parameters:
person - String the person on whom the attribute is to be defined
attribute - String the name of the attribute
value - String the value of the attribute

removeAttribute

public void removeAttribute(java.lang.String person,
                            java.lang.String attribute)
Remove an attribute from a person. If this attribute was not defined on this person, then this is silently ignored. Note that this removes the attribute altogether (that is, it doesn't just clear the value.)

Parameters:
person - String the person on whom the attribute is defined
attribute - String the name of the attribute