edu.harvard.deas.hyperenc.gui
Class MessageStorage

java.lang.Object
  extended by edu.harvard.deas.hyperenc.gui.MessageStorage
Direct Known Subclasses:
BasicMessageStorage, DBMessageStorage

public abstract class MessageStorage
extends Object

Stores collections of GuiMessages. Supports retrieval of all GuiMessages from a particular sender.

The messages stored in a MessageStorage may be stored either by value or by reference. This means that GuiMessages returned by the get* methods might not be identical to those that were originally stored, but will compare equal via the equals method. (This requirement allows for the possibility that an implementation may store messages on disk and reconstruct them later, resulting in the same message with a different object reference.)

Thread safety: Implementations of this class must be unconditionally thread-safe; concurrent access by multiple threads should be safe without the need for external synchronization.


Constructor Summary
MessageStorage()
          Default constructor.
 
Method Summary
abstract  void addMessage(GuiMessage msg)
          Put message in storage.
abstract  GuiMessage getMessage(int id)
          Get message from this storage, given its ID.
abstract  Collection<GuiMessage> getMessagesBySender(Contact contact)
          Get all stored messages sent from a particular contact.
abstract  GuiMessage removeMessage(int id)
          Remove a message from storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageStorage

public MessageStorage()
Default constructor. Does nothing.

Method Detail

addMessage

public abstract void addMessage(GuiMessage msg)
Put message in storage.

Parameters:
msg - Message to be stored.

getMessage

public abstract GuiMessage getMessage(int id)
Get message from this storage, given its ID. The ID is that given by the getID method of GuiMessage.

Parameters:
id - ID of desired message.
Returns:
the message with the given ID, or null if there is no such message stored.

getMessagesBySender

public abstract Collection<GuiMessage> getMessagesBySender(Contact contact)
Get all stored messages sent from a particular contact. Callers may mutate the returned Collection.

Parameters:
contact - contact of desired sender
Returns:
a Collection of all incoming messages from the specified sender. If there are no messages stored from the specified sender, returns an empty Collection. Changes to the returned Collection are not reflected in this MessageStorage.

removeMessage

public abstract GuiMessage removeMessage(int id)
Remove a message from storage. If there is no such message, does nothing.

Parameters:
id - ID of message to be removed.
Returns:
The message with the given ID, or null if there is no such message stored.