java.lang.Object
org.klomp.snark.comments.Comment
- All Implemented Interfaces:
Comparable<Comment>
Store a single comment and/or rating. Unmodifiable except for marking as hidden. Stores a one-second timestamp but designed so identical comments within a certain time frame (bucket) are equal. Don't store in a plain set - see
equals(Object).Field Summary
Modifier and TypeFieldDescriptionprivate static final AtomicIntegerSequence number of the created comments.private static final intWidth of the comment time buckets.private final booleanTrue if we wrote the comment.private booleanTrue to keep the comment out of the display.private final intThis comment's position in that sequence.static final intMaximum length of a commenter name.private static final intLargest clock skew accepted in a comment.private static final intLongest comment text accepted, the IRC limit more or less.private final StringThe name of the commenter.private final byteThe rating the commenter gave.private final StringThe comment text.private final intWhen the comment was written, seconds since 1/1/2005.private static final longEpoch of the comment times, 1/1/2005.private static final longFactor shrinking the bucket times.Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionintCompares comments in reverse chronological order (newest first).private static booleanCompares two possibly null strings for equality.booleanComments within 10 minutes (not necessarily in same bucket) and otherwise equal are considered equal.booleanChecks equality ignoring the timestamp, comparing only rating, text, and name.static CommentParses a comment from its persistent string representation.intgetID()Returns a unique ID for this comment, usable withCommentSet.remove(Object)int).getName()Returns the commenter's name.intReturns the rating (0-5).getText()Returns the comment text.longgetTime()Returns the comment timestamp in java time (milliseconds since epoch).inthashCode()Returns the bucket number for hash-based grouping.booleanisHidden()Returns whether this comment is hidden (deleted by the user).booleanisMine()Returns whether this comment was posted by the local user.(package private) voidMark this comment as hidden.Converts this comment to a persistent string representation.
Field Details
text
The comment text.name
The name of the commenter.time
private final int timeWhen the comment was written, seconds since 1/1/2005.rating
private final byte ratingThe rating the commenter gave.byMe
private final boolean byMeTrue if we wrote the comment._id
Sequence number of the created comments.id
private final int idThis comment's position in that sequence.MAX_NAME_LEN
public static final int MAX_NAME_LENMaximum length of a commenter name.- See Also:
MAX_TEXT_LEN
private static final int MAX_TEXT_LENLongest comment text accepted, the IRC limit more or less.- See Also:
BUCKET_SIZE
private static final int BUCKET_SIZEWidth of the comment time buckets.- See Also:
TIME_SHRINK
private static final long TIME_SHRINKFactor shrinking the bucket times.- See Also:
MAX_SKEW
private static final int MAX_SKEWLargest clock skew accepted in a comment.- See Also:
TIME_OFFSET
private static final long TIME_OFFSETEpoch of the comment times, 1/1/2005.- See Also:
Constructor Details
Comment
Comment
Create a comment with the specified text, name, rating, time, and ownership.- Parameters:
text- may be null, will be truncated to max length, newlines replaced with spacesname- may be null, will be truncated to max length, newlines and commas removedrating- 0-5time- java time (ms)isMine- whether this comment is from the local user
Method Details
getText
getName
getRating
public int getRating()Returns the rating (0-5).- Returns:
- the rating value
getTime
public long getTime()Returns the comment timestamp in java time (milliseconds since epoch).- Returns:
- the scaled offset timestamp, or 0 if the stored value is below the base offset
isMine
public boolean isMine()Returns whether this comment was posted by the local user.- Returns:
- true if the comment is from the local user
isHidden
public boolean isHidden()Returns whether this comment is hidden (deleted by the user).- Returns:
- true if hidden
setHidden
void setHidden()Mark this comment as hidden.getID
public int getID()Returns a unique ID for this comment, usable withCommentSet.remove(Object)int). Not persisted across restarts.- Returns:
- the unique ID
compareTo
Compares comments in reverse chronological order (newest first). Falls back to rating, then name, then text for ties.- Specified by:
compareToin interfaceComparable<Comment>- Parameters:
c- the other Comment to compare to- Returns:
- negative if this comment is newer
toPersistentString
Converts this comment to a persistent string representation.- Returns:
- comma-separated string of time,rating,mine,hidden,name,text
fromPersistentString
hashCode
equals
equalsIgnoreTimestamp
Checks equality ignoring the timestamp, comparing only rating, text, and name.- Parameters:
c- the other Comment to compare to- Returns:
- true if rating, text, and name match
eq