Class MessageList

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<Message>

    public class MessageList
    extends java.lang.Object
    implements java.lang.Iterable<Message>, java.io.Serializable
    Represents a List of Message objects. This class can be used to maintain a collection of such objects.
    It contains some useful additional methods to retrieve and group messages.
    The internal storage is organized using a List, so duplicates of items are allowed.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      MessageList()
      Creates a new MessageList object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(Message item)
      Adds a new Message to the list.
      void add​(MessageList items)
      Adds a new MessageList to the list.
      void clear()
      Removes all mappings from this list.
      boolean contains​(int type)
      Returns true if this list contains a message of the given type.
      The type constants are stored in Message.
      boolean contains​(int type, java.lang.String property)
      Returns true if this list contains a message of the given type and for the given property.
      The type constants are stored in Message.
      boolean contains​(Message value)
      Returns true if this list contains the specified element.
      boolean contains​(java.lang.String resourceKey)
      Returns true if this list contains a message with the given key.
      boolean equals​(java.lang.Object o)
      Compares the specified object with this list for equality.
      Message get​(int index)
      Returns the element at the specified position in this list.
      Message get​(int type, java.lang.String property)
      Retrieves the Message of the list for a given type and for the given property.
      int hashCode()
      Returns the hash code value for this list.
      boolean isEmpty()
      Returns true if this list contains no data.
      java.util.Iterator<Message> iterator()
      Returns an iterator over the elements contained in the MessageList.
      void remove​(java.lang.String resourceKey)
      Removes all messages with the given key from the list of messages.
      void remove​(java.lang.String[] resourceKeys)
      Removes all messages with the given keys from the list of messages.
      int size()
      Returns the number of elemts in this list.
      MessageList subList​(int type)
      Returns a sub list of the elements of this list, for the given selection criteria.
      MessageList subList​(int type, java.lang.String property)
      Returns a sub list of the elements of this list, for the given selection criteria.
      Message[] toArray()
      Returns the MessageList as array .
      java.lang.String toString()
      Returns a string representation of this collection.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • MessageList

        public MessageList()
        Creates a new MessageList object.
    • Method Detail

      • remove

        public void remove​(java.lang.String[] resourceKeys)
        Removes all messages with the given keys from the list of messages.
        Parameters:
        resourceKeys - resourceKeys of messages
      • remove

        public void remove​(java.lang.String resourceKey)
        Removes all messages with the given key from the list of messages.
        Parameters:
        resourceKey - resourceKey of messages
      • add

        public void add​(Message item)
        Adds a new Message to the list. If you try to add a message that is already present in the list, the new item will not be added and the method returns silently.

        Implementation note: This method performs a linear search and calls the equal() method on each item. For small amounts (less then 15) of items this may be ok. For more you should implement a better technique.
        Parameters:
        item - Message to be stored in MessageList
      • add

        public void add​(MessageList items)
        Adds a new MessageList to the list.
        If you try to add a message that is already present in the list, the item will be added again!
        Parameters:
        items - Messages to be stored in MessageList
      • get

        public Message get​(int index)
        Returns the element at the specified position in this list.
        Parameters:
        index - index of element to return
        Returns:
        the element at the specified position in this list
      • get

        public Message get​(int type,
                           java.lang.String property)

        Retrieves the Message of the list for a given type and for the given property.

        The type constants are stored in Message.

        Note If the List contains more then one Message for the given combination of type and property only the first is returned. To retrieve all entries use subList.
        Parameters:
        type - Type of message as defined in Message
        property - Name of the property the message should be associated with
        Returns:
        Message object for the given search criteria or null if no object was found.
      • clear

        public void clear()
        Removes all mappings from this list.
      • size

        public int size()
        Returns the number of elemts in this list.
        Returns:
        the number of number of elemts in this list.
      • isEmpty

        public boolean isEmpty()
        Returns true if this list contains no data.
        Returns:
        true if list contains no data.
      • contains

        public boolean contains​(Message value)
        Returns true if this list contains the specified element.
        Parameters:
        value - value whose presence in this list is to be tested.
        Returns:
        true if this list contains the specified value.
      • contains

        public boolean contains​(int type)
        Returns true if this list contains a message of the given type.
        The type constants are stored in Message.
        Parameters:
        type - Type of message as defined in Message
        Returns:
        true if message of type is present in list; otherwise false.
      • contains

        public boolean contains​(java.lang.String resourceKey)
        Returns true if this list contains a message with the given key.
        Parameters:
        resourceKey - resourceKey of message
        Returns:
        true if message of type is present in list; otherwise false.
      • contains

        public boolean contains​(int type,
                                java.lang.String property)
        Returns true if this list contains a message of the given type and for the given property.
        The type constants are stored in Message.
        Parameters:
        type - Type of message as defined in Message
        property - Name of the property the message should be associated with
        Returns:
        true if message of type is present in list; otherwise false.
      • iterator

        public java.util.Iterator<Message> iterator()
        Returns an iterator over the elements contained in the MessageList.
        Specified by:
        iterator in interface java.lang.Iterable<Message>
        Returns:
        Iterator for this object
      • toArray

        public Message[] toArray()
        Returns the MessageList as array .
        Returns:
        message array
      • subList

        public MessageList subList​(int type,
                                   java.lang.String property)

        Returns a sub list of the elements of this list, for the given selection criteria. All Message elemenets of the list for the given type and the given property are extracted and returned in a new object. If there are no elements matching the criteria null is returned.

        Note Only a shallow copy is performed. Both lists are containig references to the same objects in memory.

        Parameters:
        type - Type of message as defined in Message
        property - Name of the property the message should be associated with
        Returns:
        MessageList object for the given search criteria or null if no object was found.
      • subList

        public MessageList subList​(int type)

        Returns a sub list of the elements of this list, for the given selection criteria. All Message elemenets of the list for the given type are extracted and returned in a new object. If there are no elements matching the criteria null is returned.

        Note Only a shallow copy is performed. Both lists are containig references to the same objects in memory.

        Parameters:
        type - Type of message as defined in Message
        Returns:
        MessageList object for the given search criteria or null if no object was found.
      • equals

        public boolean equals​(java.lang.Object o)

        Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order.

        This implementation first checks if the specified object is this list. If so, it returns true; if not, it checks if the specified object is a list. If not, it returns false; if so, it iterates over both lists, comparing corresponding pairs of elements. If any comparison returns false, this method returns false. If either iterator runs out of elements before the other it returns false (as the lists are of unequal length); otherwise it returns true when the iterations complete.

        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - the object to be compared for equality with this list.
        Returns:
        true if the specified object is equal to this list.
      • hashCode

        public int hashCode()
        Returns the hash code value for this list. The hash code of a list is defined to be the result of the following calculation:
         hashCode = 1;
         Iterator i = list.iterator();
         while (i.hasNext())
         {
                Object obj = i.next();
                hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
         }
         
        This ensures that list1.equals(list2) implies that list1.hashCode()==list2.hashCode() for any two lists, list1 and list2, as required by the general contract of Object.hashCode.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code value for this list.
      • toString

        public java.lang.String toString()

        Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String.valueOf(Object).

        This implementation creates an empty string buffer, appends a left square bracket, and iterates over the collection appending the string representation of each element in turn. After appending each element except the last, the string ", " is appended. Finally a right bracket is appended. A string is obtained from the string buffer, and returned.

        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of this collection