Module whatsapp4j

Class Messages

All Implemented Interfaces:
Serializable, Cloneable, Iterable<MessageInfo>, Collection<MessageInfo>, List<MessageInfo>, RandomAccess

public class Messages extends ArrayList<MessageInfo>
This class is an implementation of ArrayList used to store the Message in a Chat. The messages stored in this collection are guaranteed to be stored chronologically. This contract can be technically broken using reflection to access the array associated with this collection, though, obviously, it's not advisable.
See Also:
  • Constructor Details

    • Messages

      public Messages(@NonNull @NonNull MessageInfo message)
      Constructs a new instance of WebMessageInfos from a WebMessageInfo
      Parameters:
      message - the first non null entry to add to this collection
    • Messages

      public Messages()
  • Method Details

    • add

      public boolean add(@NonNull @NonNull MessageInfo message)
      Adds message to this collection in the right position in order to respect the contract explained previously
      Specified by:
      add in interface Collection<MessageInfo>
      Specified by:
      add in interface List<MessageInfo>
      Overrides:
      add in class ArrayList<MessageInfo>
      Parameters:
      message - the non null message to add to this collection
      Returns:
      true if message was added successfully
    • addOrReplace

      public boolean addOrReplace(@NonNull @NonNull MessageInfo message)
      Adds message if no other entry in this collection has an jid that matches the one of message. Otherwise, it removes said entry and adds message.
      Parameters:
      message - the non null message to add to this collection
      Returns:
      true if message was replaced
    • addAll

      public boolean addAll(Collection<? extends MessageInfo> collection)
      Adds each entry of collection if no other entry in this collection has an jid that matches said entry's. Otherwise, it removes said entry and adds said entry.
      Specified by:
      addAll in interface Collection<MessageInfo>
      Specified by:
      addAll in interface List<MessageInfo>
      Overrides:
      addAll in class ArrayList<MessageInfo>
      Parameters:
      collection - the collection to add to this collection
    • add

      public void add(int index, MessageInfo element)
      This method is not supported for this collection because of the contract previously explained
      Specified by:
      add in interface List<MessageInfo>
      Overrides:
      add in class ArrayList<MessageInfo>
      Throws:
      UnsupportedOperationException - this exception will always be thrown
    • addAll

      public boolean addAll(int index, Collection<? extends MessageInfo> c)
      This method is not supported for this collection because of the contract previously explained
      Specified by:
      addAll in interface List<MessageInfo>
      Overrides:
      addAll in class ArrayList<MessageInfo>
      Throws:
      UnsupportedOperationException - this exception will always be thrown