Class MessageList
- java.lang.Object
-
- de.hybris.platform.sap.core.common.message.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 ofMessageobjects. 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 newMessageListobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Message item)Adds 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.booleancontains(int type, java.lang.String property)Returnstrueif this list contains a message of the given type and for the given property.
The type constants are stored inMessage.booleancontains(Message value)Returnstrueif this list contains the specified element.booleancontains(java.lang.String resourceKey)Returnstrueif this list contains a message with the given key.booleanequals(java.lang.Object o)Compares the specified object with this list for equality.Messageget(int index)Returns the element at the specified position in this list.Messageget(int type, java.lang.String property)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.java.util.Iterator<Message>iterator()Returns an iterator over the elements contained in theMessageList.voidremove(java.lang.String resourceKey)Removes all messages with the given key from the list of messages.voidremove(java.lang.String[] resourceKeys)Removes all messages with the given keys from the list of messages.intsize()Returns the number of elemts in this list.MessageListsubList(int type)Returns a sub list of the elements of this list, for the given selection criteria.MessageListsubList(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.StringtoString()Returns a string representation of this collection.
-
-
-
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 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
public void add(MessageList items)
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
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
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
public boolean contains(Message value)
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
public boolean contains(java.lang.String resourceKey)
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
public boolean contains(int type, java.lang.String property)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
public java.util.Iterator<Message> iterator()
Returns an iterator over the elements contained in theMessageList.- Specified by:
iteratorin interfacejava.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
Messageelemenets of the list for the given type and the given property are extracted and returned in a newobject. If there are no elements matching the criteria nullis 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
public MessageList subList(int type)
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 newobject. If there are no elements matching the criteria nullis 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
public boolean equals(java.lang.Object o)
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.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the object to be compared for equality with this list.- Returns:
trueif 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 thatlist1.equals(list2)implies thatlist1.hashCode()==list2.hashCode()for any two lists,list1andlist2, as required by the general contract ofObject.hashCode.- Overrides:
hashCodein classjava.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:
toStringin classjava.lang.Object- Returns:
- a string representation of this collection
-
-