Class MessageList
- All Implemented Interfaces:
Serializable,Iterable<Message>
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a newMessageto the list.voidadd(MessageList items) Adds a newMessageListto the list.voidclear()Removes all mappings from this list.booleancontains(int type) Returnstrueif this list contains a message of the given type.
The type constants are stored inMessage.booleanReturnstrueif this list contains a message of the given type and for the given property.
The type constants are stored inMessage.booleanReturnstrueif this list contains the specified element.booleanReturnstrueif this list contains a message with the given key.booleanCompares the specified object with this list for equality.get(int index) Returns the element at the specified position in this list.Retrieves theMessageof the list for a given type and for the given property.inthashCode()Returns the hash code value for this list.booleanisEmpty()Returns true if this list contains no data.iterator()Returns an iterator over the elements contained in theMessageList.voidRemoves all messages with the given key from the list of messages.voidRemoves all messages with the given keys from the list of messages.intsize()Returns the number of elemts in this list.subList(int type) Returns a sub list of the elements of this list, for the given selection criteria.Returns a sub list of the elements of this list, for the given selection criteria.Message[]toArray()Returns the MessageList as array .toString()Returns a string representation of this collection.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
MessageList
public MessageList()Creates a newMessageListobject.
-
-
Method Details
-
remove
Removes all messages with the given keys from the list of messages.- Parameters:
resourceKeys- resourceKeys of messages
-
remove
Removes all messages with the given key from the list of messages.- Parameters:
resourceKey- resourceKey of messages
-
add
Adds a newMessageto 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 inMessageList
-
add
Adds a newMessageListto 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 inMessageList
-
get
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
Retrieves the
Messageof the list for a given type and for the given property.The type constants are stored in
Note If the List contains more then oneMessage.Messagefor the given combination of type and property only the first is returned. To retrieve all entries usesubList.- Parameters:
type- Type of message as defined inMessageproperty- Name of the property the message should be associated with- Returns:
Messageobject for the given search criteria ornullif 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:
trueif list contains no data.
-
contains
Returnstrueif this list contains the specified element.- Parameters:
value- value whose presence in this list is to be tested.- Returns:
trueif this list contains the specified value.
-
contains
public boolean contains(int type) Returnstrueif this list contains a message of the given type.
The type constants are stored inMessage.- Parameters:
type- Type of message as defined inMessage- Returns:
trueif message of type is present in list; otherwisefalse.
-
contains
Returnstrueif this list contains a message with the given key.- Parameters:
resourceKey- resourceKey of message- Returns:
trueif message of type is present in list; otherwisefalse.
-
contains
Returnstrueif this list contains a message of the given type and for the given property.
The type constants are stored inMessage.- Parameters:
type- Type of message as defined inMessageproperty- Name of the property the message should be associated with- Returns:
trueif message of type is present in list; otherwisefalse.
-
iterator
Returns an iterator over the elements contained in theMessageList. -
toArray
Returns the MessageList as array .- Returns:
- message array
-
subList
Returns a sub list of the elements of this list, for the given selection criteria. All
Messageelemenets of the list for the given type and the given property are extracted and returned in a new <codeMessageList object. If there are no elements matching the criterianullis 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 inMessageproperty- Name of the property the message should be associated with- Returns:
MessageListobject for the given search criteria ornullif no object was found.
-
subList
Returns a sub list of the elements of this list, for the given selection criteria. All
Messageelemenets of the list for the given type are extracted and returned in a new <codeMessageList object. If there are no elements matching the criterianullis 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 inMessage- Returns:
MessageListobject for the given search criteria ornullif no object was found.
-
equals
Compares the specified object with this list for equality. Returns
trueif 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 elementse1ande2are 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 returnsfalse; if so, it iterates over both lists, comparing corresponding pairs of elements. If any comparison returnsfalse, this method returnsfalse. If either iterator runs out of elements before the other it returnsfalse(as the lists are of unequal length); otherwise it returns true when the iterations complete. -
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 thatlist1.equals(list2)implies thatlist1.hashCode()==list2.hashCode()for any two lists,list1andlist2, as required by the general contract ofObject.hashCode. -
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.
-