java.lang.Object
net.i2p.util.UIMessages
A queue of messages, where each has an ID number. Provide the ID back to the clear call, so you don't erase messages you haven't seen yet.
Thread-safe.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a single UI message with a unique identifier.Field Summary
FieldsModifier and TypeFieldDescriptionprivate intMessage count the cache was built at.Rendered messages, rebuilt when they change.private intId the next message will get.private final intMost messages kept before the oldest is dropped.private final LinkedList<UIMessages.Message> The messages still being shown.Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionintaddMessage(String message) Will remove an old message if over the max size.intaddMessageNoEscape(String message) Use if it includes a link.voidclear()Remove all messages from the queue.voidclearThrough(int id) Remove all messages up to and including the given id.intThe ID of the last message added, or -1 if never.Newest last, or empty list.Newest last, or empty list.booleanisEmpty()Check if there are any messages.
Field Details
_maxSize
private final int _maxSizeMost messages kept before the oldest is dropped._count
private int _countId the next message will get._messages
The messages still being shown._cachedStrings
_cachedCount
private int _cachedCountMessage count the cache was built at.
Constructor Details
UIMessages
public UIMessages(int maxSize) Message buffer with the given capacity.- Parameters:
maxSize- the maximum number of messages to keep
Method Details
addMessage
Will remove an old message if over the max size. Use if it does not include a link. Escapes '<' and '>' before queueing.- Parameters:
message- text to queue, HTML-escaped before storage- Returns:
- the message id
addMessageNoEscape
Use if it includes a link. Does not escape '<' and '>' before queueing.- Parameters:
message- text to queue verbatim, so it may carry markup such as a link- Returns:
- the message id
getLastMessageID
public int getLastMessageID()The ID of the last message added, or -1 if never.- Returns:
- the last message i d
getMessages
Newest last, or empty list. Provide id of last one back toclearThrough(int).- Returns:
- a new list of the retained messages, newest last; empty if none
getMessageStrings
clear
public void clear()Remove all messages from the queue.clearThrough
public void clearThrough(int id) Remove all messages up to and including the given id.- Parameters:
id- message id to clear through
isEmpty
public boolean isEmpty()Check if there are any messages.- Returns:
- true if no messages remain, false otherwise