public class CommentSet extends AbstractSet<Comment>
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.
| Modifier and Type | Field and Description |
|---|---|
static int | MAX_SIZEMaximum number of comments allowed |
| Constructor and Description |
|---|
CommentSet(Collection<Comment> coll)Creates a CommentSet from a collection of comments. |
CommentSet(File file)Creates a CommentSet by reading from a gzipped file. |
| Modifier and Type | Method and Description |
|---|---|
boolean | add(Comment c)Adds a comment to this set. |
void | clear()Clears all comments including hidden ones. |
double | getAverageRating()Returns the average rating from all non-hidden, non-local comments. |
long | getLatestCommentTime()Returns the timestamp of the most recent non-hidden comment. |
int | getMyRating()Returns the local user's rating, or 0 if none. |
int | getRatingCount()Returns the number of ratings making up the average rating. |
boolean | isModified()Returns whether this set has been modified since instantiation or last save. |
Iterator<Comment> | iterator()Returns an iterator over non-hidden comments in reverse-sort order (newest first). |
boolean | remove(int id)Hides a comment by its unique ID (as returned by Comment.getID()). |
boolean | remove(Object o)Hides a comment (does not actually remove it from the underlying set). |
void | save(File file)Saves this CommentSet to a gzipped file. |
int | size()Returns the number of non-hidden comments. |
equals, hashCode, removeAlladdAll, contains, containsAll, isEmpty, retainAll, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitaddAll, contains, containsAll, isEmpty, retainAll, spliterator, toArray, toArrayparallelStream, removeIf, streampublic static final int MAX_SIZE
public CommentSet(Collection<Comment> coll)
coll - the initial collection of commentspublic CommentSet(File file) throws IOException
file - the gzipped file to read fromIOException - if an I/O error occurspublic boolean add(Comment c)
add in interface Collection<Comment>add in interface Set<Comment>add in class AbstractCollection<Comment>c - the comment to addpublic void clear()
clear in interface Collection<Comment>clear in interface Set<Comment>clear in class AbstractCollection<Comment>public double getAverageRating()
public long getLatestCommentTime()
public int getMyRating()
public int getRatingCount()
public boolean isModified()
public Iterator<Comment> iterator()
Returned values may be fewer than size() due to additional deduping.
public boolean remove(int id)
id - the comment ID to hidepublic boolean remove(Object o)
remove in interface Collection<Comment>remove in interface Set<Comment>remove in class AbstractCollection<Comment>o - the Comment to hidepublic void save(File file) throws IOException
file - the file to write toIOException - if an I/O error occurspublic int size()
size in interface Collection<Comment>size in interface Set<Comment>size in class AbstractCollection<Comment>