FakeDataAdapterpublic class FakeDataAdapter extends DataAdapter
Fields Summary |
---|
private List | allBoards | private static long | nextMessageID | private Map | messageMap |
Constructors Summary |
---|
public FakeDataAdapter()
this.allBoards = new ArrayList();
BoardSummary bs0 = new BoardSummaryImpl(0L,
"Java Programming",
"General programming questions about Java.");
BoardSummary bs1 = new BoardSummaryImpl(1L,
"XSLT Stylesheet Techniques",
"Writing effective XSLT stylesheets.");
this.allBoards.add(bs0);
this.allBoards.add(bs1);
this.postNewMessage(0L, "First subject in Java Prog",
"burke_e@yahoo.com", "Sample message text");
|
Methods Summary |
---|
public java.util.Iterator | getAllBoards()
return this.allBoards.iterator();
| public java.util.Iterator | getAllMessages(long boardID, MonthYear month)If no messages exist for the specified board and month, return
an empty iterator.
// this is slow, but works fine for a fake implementation
List msgs = new ArrayList();
Iterator iter = this.messageMap.values().iterator();
while (iter.hasNext()) {
MessageSummary curMsg = (MessageSummary) iter.next();
if (curMsg.getBoard().getID() == boardID
&& month.containsInMonth(curMsg.getCreateDate())) {
msgs.add(curMsg);
}
}
return msgs.iterator();
| public BoardSummary | getBoardSummary(long boardID)
Iterator iter = getAllBoards();
while (iter.hasNext()) {
BoardSummary curBoard = (BoardSummary) iter.next();
if (curBoard.getID() == boardID) {
return curBoard;
}
}
throw new DataException("Illegal boardID: " + boardID);
| public Message | getMessage(long msgID)
Message msg = (Message) this.messageMap.get(new Long(msgID));
if (msg != null) {
return msg;
}
throw new DataException("Invalid msgID");
| private static synchronized long | getNextMessageID()
nextMessageID++;
return nextMessageID;
| public Message | postNewMessage(long boardID, java.lang.String msgSubject, java.lang.String authorEmail, java.lang.String msgText)Post a new message.
BoardSummary boardSum = getBoardSummary(boardID);
long msgID = getNextMessageID();
Message msg = new MessageImpl(msgID, new DayMonthYear(), boardSum,
msgSubject, authorEmail, msgText, -1);
this.messageMap.put(new Long(msg.getID()), msg);
((BoardSummaryImpl) boardSum).messageAdded(msg);
return msg;
| public Message | replyToMessage(long origMsgID, java.lang.String msgSubject, java.lang.String authorEmail, java.lang.String msgText)Add a reply to an existing message.
MessageSummary origMsg = getMessage(origMsgID);
long msgID = getNextMessageID();
Message msg = new MessageImpl(msgID, new DayMonthYear(), origMsg.getBoard(),
msgSubject, authorEmail, msgText, origMsgID);
this.messageMap.put(new Long(msg.getID()), msg);
return msg;
|
|