edu.harvard.deas.hyperenc.gui
Class BasicMessageStorage

java.lang.Object
  extended by edu.harvard.deas.hyperenc.gui.MessageStorage
      extended by edu.harvard.deas.hyperenc.gui.BasicMessageStorage

public class BasicMessageStorage
extends MessageStorage

Stores collections of GuiMessages. Supports retrieval of all GuiMessages from a particular sender. This implementation is backed by the Java Collections API. It is not backed by any persistent medium, and so the contained messages will be lost when the VM terminates unless the application explicitly writes the contained messages to disk.

All storage in this MessageStorage is done by reference; the returned GuiMessage is the same object reference as the one that was stored.

Thread safety: This implementation is unconditionally thread-safe.


Constructor Summary
BasicMessageStorage()
          Constructs a new, empty BasicMessageStorage.
 
Method Summary
 void addMessage(GuiMessage msg)
          Put message in storage.
 GuiMessage getMessage(int id)
          Get message from this storage, given its ID.
 Collection<GuiMessage> getMessagesBySender(Contact contact)
          Get all stored messages sent from a particular contact.
 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

BasicMessageStorage

public BasicMessageStorage()
Constructs a new, empty BasicMessageStorage.

Method Detail

addMessage

public void addMessage(GuiMessage msg)
Description copied from class: MessageStorage
Put message in storage.

Specified by:
addMessage in class MessageStorage
Parameters:
msg - Message to be stored.

getMessage

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

Specified by:
getMessage in class MessageStorage
Parameters:
id - ID of desired message.
Returns:
the message with the given ID, or null if there is no such message stored.

getMessagesBySender

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

Specified by:
getMessagesBySender in class MessageStorage
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 GuiMessage removeMessage(int id)
Description copied from class: MessageStorage
Remove a message from storage. If there is no such message, does nothing.

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