001: package pygmy.nntp.http;
002:
003: import pygmy.core.UUID;
004:
005: import java.util.*;
006:
007: public class ForumMessage {
008:
009: UUID guid;
010:
011: UUID parentGuid;
012:
013: String subject;
014:
015: String contents;
016:
017: String author;
018:
019: Date postDate;
020:
021: UUID topicGuid;
022:
023: ArrayList replies = new ArrayList();
024:
025: public ForumMessage(String subject, String author, String contents) {
026: this (null, subject, author, contents);
027: }
028:
029: public ForumMessage(UUID parentGuid, String subject, String author,
030: String contents) {
031: this (UUID.createUUID(), parentGuid, subject, author,
032: new Date(), contents);
033: }
034:
035: public ForumMessage(UUID messageGuid, UUID parentGuid,
036: String subject, String author, Date postDate,
037: String contents) {
038: this .guid = messageGuid;
039: this .parentGuid = parentGuid;
040: this .subject = subject;
041: this .contents = contents;
042: this .author = author;
043: this .postDate = postDate;
044: }
045:
046: public boolean equals(Object o) {
047: if (this == o)
048: return true;
049: if (!(o instanceof ForumMessage))
050: return false;
051:
052: final ForumMessage forumMessage = (ForumMessage) o;
053:
054: if (!guid.equals(forumMessage.guid))
055: return false;
056:
057: return true;
058: }
059:
060: public int hashCode() {
061: return guid.hashCode();
062: }
063:
064: public UUID getGuid() {
065: return guid;
066: }
067:
068: public UUID getParentGuid() {
069: return parentGuid;
070: }
071:
072: public String getContents() {
073: return contents;
074: }
075:
076: public String getAuthor() {
077: return author;
078: }
079:
080: public Date getPostDate() {
081: return postDate;
082: }
083:
084: public String getSubject() {
085: return subject;
086: }
087:
088: public void addToThread(ForumMessage message) {
089: int insertionPoint = Collections.binarySearch(replies, message,
090: new MessageDateComparator());
091: if (insertionPoint < 0) {
092: replies.add(Math.abs(insertionPoint + 1), message);
093: }
094: }
095:
096: public int getThreadSize() {
097: return replies.size();
098: }
099:
100: public boolean isReply() {
101: return parentGuid != null;
102: }
103:
104: public Iterator threadIterator() {
105: return replies.iterator();
106: }
107:
108: public void setTopicGuid(UUID topicGuid) {
109: this .topicGuid = topicGuid;
110: }
111:
112: public String getUrl() {
113: return "/read?message=" + getGuid() + "&topic=" + topicGuid;
114: }
115:
116: public String getReplyUrl() {
117: return "/post?message=" + getGuid() + "&topic=" + topicGuid;
118: }
119: }
|