Package org.klomp.snark.comments
Class CommentSet
public class CommentSet extends AbstractSet<Comment>
Store comments.
Optimized for fast checking of duplicates, and retrieval of ratings.
Removes are not really removed, only marked as hidden, so
they don't reappear.
Duplicates are detected based on an approximate time range.
Max size of both elements and total text length is enforced.
Supports persistence via save() and File constructor.
NOT THREAD SAFE except for iterating AFTER the iterator() call.
- Since:
- 0.9.31
-
Field Summary
Fields Modifier and Type Field Description static intMAX_SIZE -
Constructor Summary
Constructors Constructor Description CommentSet(File file)File must be gzipped.CommentSet(Collection<Comment> coll) -
Method Summary
Modifier and Type Method Description booleanadd(Comment c)Max length for strings enforced in Comment.java.voidclear()Actually clears everything, including hidden.doublegetAverageRating()longgetLatestCommentTime()Is not adjusted if the latest comment wasn't hidden but is then hidden.intgetMyRating()intgetRatingCount()booleanisModified()Iterator<Comment>iterator()Will be in reverse-sort order, i.e.booleanremove(int id)Remove the id as retrieved from Comment.getID().booleanremove(Object o)Only hides the comment, doesn't really remove it.voidsave(File file)File will be gzipped.intsize()May be more than what the iterator returns, we do additional deduping in the iterator.Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Set
addAll, contains, containsAll, isEmpty, retainAll, spliterator, toArray, toArray
-
Field Details
-
MAX_SIZE
public static final int MAX_SIZE- See Also:
- Constant Field Values
-
-
Constructor Details
-
CommentSet
-
CommentSet
File must be gzipped. Need not be sorted. See Comment.toPersistentString() for format.- Throws:
IOException
-
-
Method Details
-
save
File will be gzipped. Not sorted, includes hidden. See Comment.toPersistentString() for format. Sets isModified() to false.- Throws:
IOException
-
add
Max length for strings enforced in Comment.java. Max total length for strings enforced here. Enforces max size for set- Specified by:
addin interfaceCollection<Comment>- Specified by:
addin interfaceSet<Comment>- Overrides:
addin classAbstractCollection<Comment>
-
remove
Only hides the comment, doesn't really remove it.- Specified by:
removein interfaceCollection<Comment>- Specified by:
removein interfaceSet<Comment>- Overrides:
removein classAbstractCollection<Comment>- Returns:
- true if present and not previously hidden
-
remove
public boolean remove(int id)Remove the id as retrieved from Comment.getID(). Only hides the comment, doesn't really remove it. This is for the UI.- Returns:
- true if present and not previously hidden
-
getLatestCommentTime
public long getLatestCommentTime()Is not adjusted if the latest comment wasn't hidden but is then hidden.- Returns:
- the timestamp of the most recent non-hidden comment
-
isModified
public boolean isModified()- Returns:
- true if modified since instantiation
-
getMyRating
public int getMyRating()- Returns:
- 0 if none, or 1-5
-
getRatingCount
public int getRatingCount()- Returns:
- Number of ratings making up the average rating
-
getAverageRating
public double getAverageRating()- Returns:
- 0 if none, or 1-5
-
clear
public void clear()Actually clears everything, including hidden. Resets ratings to zero.- Specified by:
clearin interfaceCollection<Comment>- Specified by:
clearin interfaceSet<Comment>- Overrides:
clearin classAbstractCollection<Comment>
-
size
public int size()May be more than what the iterator returns, we do additional deduping in the iterator.- Specified by:
sizein interfaceCollection<Comment>- Specified by:
sizein interfaceSet<Comment>- Specified by:
sizein classAbstractCollection<Comment>- Returns:
- the non-hidden size
-
iterator
Will be in reverse-sort order, i.e. newest-first. The returned iterator is thread-safe after this call. Changes after this call will not be reflected in the iterator. iter.remove() has no effect on the underlying set. Hidden comments not included. Returned values may be less than indicated in size() due to additional deduping in the iterator.
-