java.lang.Object
net.i2p.util.UIMessages

public class UIMessagesextends Object
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.

  • Field Details

    • _maxSize

      private final int _maxSize
      Most messages kept before the oldest is dropped.
    • _count

      private int _count
      Id the next message will get.
    • _messages

      private final LinkedList<UIMessages.Message> _messages
      The messages still being shown.
    • _cachedStrings

      private List<String> _cachedStrings
      Rendered messages, rebuilt when they change.
    • _cachedCount

      private int _cachedCount
      Message 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

      public int addMessage(String message)
      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

      public int addMessageNoEscape(String message)
      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

      public List<UIMessages.Message> getMessages()
      Newest last, or empty list. Provide id of last one back to clearThrough(int).
      Returns:
      a new list of the retained messages, newest last; empty if none
    • getMessageStrings

      public List<String> getMessageStrings()
      Newest last, or empty list.
      Returns:
      a copy (cached)
    • 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