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_SIZE |
| Constructor and Description |
|---|
CommentSet(Collection<Comment> coll) |
CommentSet(File file)
File must be gzipped.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(Comment c)
Max length for strings enforced in Comment.java.
|
void |
clear()
Actually clears everything, including hidden.
|
double |
getAverageRating() |
long |
getLatestCommentTime()
Is not adjusted if the latest comment wasn't hidden but is then hidden.
|
int |
getMyRating() |
int |
getRatingCount() |
boolean |
isModified() |
Iterator<Comment> |
iterator()
Will be in reverse-sort order, i.e.
|
boolean |
remove(int id)
Remove the id as retrieved from Comment.getID().
|
boolean |
remove(Object o)
Only hides the comment, doesn't really remove it.
|
void |
save(File file)
File will be gzipped.
|
int |
size()
May be more than what the iterator returns, we do additional deduping in the iterator.
|
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)
public CommentSet(File file) throws IOException
IOExceptionpublic boolean add(Comment c)
add in interface Collection<Comment>add in interface Set<Comment>add in class AbstractCollection<Comment>public 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 less than indicated in size() due to additional deduping in the iterator.
public boolean remove(int id)
public boolean remove(Object o)
remove in interface Collection<Comment>remove in interface Set<Comment>remove in class AbstractCollection<Comment>public void save(File file) throws IOException
IOExceptionpublic int size()
size in interface Collection<Comment>size in interface Set<Comment>size in class AbstractCollection<Comment>