Package org.faktorips.runtime
Class MessageList
- java.lang.Object
-
- org.faktorips.runtime.MessageList
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<Message>
public class MessageList extends java.lang.Object implements java.io.Serializable, java.lang.Iterable<Message>
A list ofMessages.- See Also:
Message, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MessageList()Creates an empty message list.MessageList(Message message)Creates a message list that contains the given message.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(Message message)Adds the message to the list.voidadd(MessageList messageList)Adds the messages in the given list to this list.voidadd(MessageList messageList, ObjectProperty invalidObjectProperty, boolean override)Copies the messages from the given list to this list and sets the message's invalid object properties.voidclear()Removes all of the messages from this list.booleancontainsErrorMsg()Returns true if one the messages in the list is an error message, otherwise false.static MessageListcreateCopy(MessageList list, java.lang.Object oldObject, java.lang.Object newObject)Creates a copy from the message list and replaces all references to the old object with the new object.static MessageListcreateCopy(MessageList list, java.util.Map<ObjectProperty,ObjectProperty> objectPropertyMap)Creates a copy from the message list and replaces all references to the old object with the new object.protected MessageListcreateEmptyMessageList()Creates a new empty message list.booleanequals(java.lang.Object obj)MessagegetFirstMessage(Severity severity)Returns the first message with the given severity or null if none is found.MessagegetMessage(int index)Returns the message at the indicated index (indexing starts with 0).MessagegetMessageByCode(java.lang.String code)Returns the first message in the list that has the specified message code.java.util.List<Message>getMessages()Returns the message list.MessageListgetMessagesByCode(java.lang.String code)Returns a new message list containing all the message in this list that have the specified message code.MessageListgetMessagesByMarker(java.util.function.Predicate<IMarker> markerPredicate)Returns a new message list containing all the message in this list with aIMarkerthe specifiedPredicatematches.MessageListgetMessagesByMarker(IMarker marker)Returns a new message list containing all the message in this list that have the specifiedIMarker.MessageListgetMessagesByMarker(IPredicate<IMarker> markerPredicate)Deprecated.for removal since 21.6; UsegetMessagesByMarker(Predicate)with the Java 8Predicateinstead.MessageListgetMessagesBySeverity(Severity severity)Returns a newMessageListcontaining only theMessages with the indicated severity.MessageListgetMessagesFor(java.lang.Object object)Returns a new list with the messages in this list that belong to the given object (any property).MessageListgetMessagesFor(java.lang.Object object, java.lang.String property)Returns a new list with the messages in this list that belong to the given object and property.MessageListgetMessagesFor(java.lang.Object object, java.lang.String property, int index)Returns a new list with the messages in this list that belong to the given object and property and the property is of the given index.MessagegetMessageWithHighestSeverity()Returns the message with the highest severity.intgetNoOfMessages()Deprecated.Use #size() insteadintgetNoOfMessages(Severity severity)Returns the number of messages in this list that have the indicated severity.SeveritygetSeverity()Returns the message list's severity.MessageListgetSubList(int maxCount)The method returns a MethodList containing a sublist of messages of this messageList.java.lang.StringgetText()Returns the text of all messages in the list, separated by the system's default line separator.inthashCode()booleanisEmpty()Returns true if the list is empty.java.util.Iterator<Message>iterator()Returns an iterator over the messages in this list.MessageListmap(java.util.function.Predicate<Message> shouldBeTransformed, java.util.function.UnaryOperator<Message> transformer)Returns a new message list containing the same number of messages as this list, with the given transformer function applied to each message that matches the given predicate.MessageListmap(java.util.function.UnaryOperator<Message> transformer)Returns a new message list containing the same number of messages as this list, with the given transformer function applied to each message.MessagenewError(java.lang.String code, java.lang.String text, java.lang.Object invalidObject, java.lang.String... invalidProperties)Creates and returns a new message with severityMessage.ERRORwith the given code, text and object properties and adds the message to the list.MessagenewError(java.lang.String code, java.lang.String text, ObjectProperty... invalidObjectProperty)Creates and returns a new message with severityMessage.ERRORwith the given code, text and invalid object properties and adds the message to the list.MessagenewInfo(java.lang.String code, java.lang.String text, java.lang.Object invalidObject, java.lang.String invalidProperty)Creates and returns a new message with severityMessage.INFOwith the given code, text and object properties and adds the message to the list.MessagenewWarning(java.lang.String code, java.lang.String text, java.lang.Object invalidObject, java.lang.String... invalidProperties)Creates and returns a new message with severityMessage.WARNINGwith the given code, text and object properties and adds the message to the list.static MessageListof(Message... messages)Returns a newMessageListthat consists of the givenMessages.static MessageListofErrors(java.lang.String... texts)Returns a newMessageListthat contains error messages with the given texts.java.util.stream.Stream<Message>parallelStream()Returns a parallelStreamof the included messages.voidremove(Message message)Removes the given message from this message list.voidsetMessages(java.util.List<Message> messages)Sets the message list.intsize()Returns the total number of messages in the list.java.util.Spliterator<Message>spliterator()Creates aSpliteratorover the included messages.java.util.stream.Stream<Message>stream()Returns a sequentialStreamof the included messages.java.lang.StringtoString()Returns all messages in the list separated by a line separator.voidwrapUpMessages(java.lang.String messageCode)Finds all the messages with the messageCodes at the messageList and merge the ObjectProperties from the same messageTexts together.
-
-
-
Constructor Detail
-
MessageList
public MessageList()
Creates an empty message list.
-
MessageList
public MessageList(Message message)
Creates a message list that contains the given message.- Parameters:
message- the message to add. Ignored ifnull.
-
-
Method Detail
-
createEmptyMessageList
protected MessageList createEmptyMessageList()
Creates a new empty message list.
-
of
public static final MessageList of(Message... messages)
Returns a newMessageListthat consists of the givenMessages. Returns an emptyMessageListifnullis given.- Parameters:
messages- theMessagesthat the newMessageListwill contain. May benull- Returns:
- a new
MessageListthat consist of the givenMessages
-
ofErrors
public static final MessageList ofErrors(java.lang.String... texts)
Returns a newMessageListthat contains error messages with the given texts. Returns an emptyMessageListifnullor an empty array is given.- Parameters:
texts- the texts of the error messages in the newMessageList. May benullor empty- Returns:
- a new
MessageListthat contains error messages with the given texts or an emptyMessageList
-
createCopy
public static final MessageList createCopy(MessageList list, java.lang.Object oldObject, java.lang.Object newObject)
Creates a copy from the message list and replaces all references to the old object with the new object.- Parameters:
list- the list to copyoldObject- the old object reference that should be replaced.newObject- the object reference to set
-
createCopy
public static final MessageList createCopy(MessageList list, java.util.Map<ObjectProperty,ObjectProperty> objectPropertyMap)
Creates a copy from the message list and replaces all references to the old object with the new object.- Parameters:
objectPropertyMap- TheMapbetween old and newObjectProperty- Returns:
- MessageList
-
add
public void add(Message message)
Adds the message to the list.- Parameters:
message- the message to add. Ignored ifnull.
-
add
public void add(MessageList messageList)
Adds the messages in the given list to this list.
-
add
public void add(MessageList messageList, ObjectProperty invalidObjectProperty, boolean override)
Copies the messages from the given list to this list and sets the message's invalid object properties.- Parameters:
messageList- the list to copy the messages from.invalidObjectProperty- the object and it's property that the messages refer to.override-trueif the invalidObjectProperty should be set in all messages.falseif the invalidObjectProperty is set only for messages that do not contain any invalid object property information.
-
newError
public Message newError(java.lang.String code, java.lang.String text, java.lang.Object invalidObject, java.lang.String... invalidProperties)
Creates and returns a new message with severityMessage.ERRORwith the given code, text and object properties and adds the message to the list.
-
newError
public Message newError(java.lang.String code, java.lang.String text, ObjectProperty... invalidObjectProperty)
Creates and returns a new message with severityMessage.ERRORwith the given code, text and invalid object properties and adds the message to the list.
-
newWarning
public Message newWarning(java.lang.String code, java.lang.String text, java.lang.Object invalidObject, java.lang.String... invalidProperties)
Creates and returns a new message with severityMessage.WARNINGwith the given code, text and object properties and adds the message to the list.
-
newInfo
public Message newInfo(java.lang.String code, java.lang.String text, java.lang.Object invalidObject, java.lang.String invalidProperty)
Creates and returns a new message with severityMessage.INFOwith the given code, text and object properties and adds the message to the list.
-
isEmpty
public boolean isEmpty()
Returns true if the list is empty.
-
size
public int size()
Returns the total number of messages in the list.
-
getMessage
public Message getMessage(int index)
Returns the message at the indicated index (indexing starts with 0).- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of range.
-
getNoOfMessages
@Deprecated public int getNoOfMessages()
Deprecated.Use #size() insteadReturns the number of messages in the list.
-
getMessages
public java.util.List<Message> getMessages()
Returns the message list.
-
setMessages
public void setMessages(java.util.List<Message> messages)
Sets the message list.
-
getFirstMessage
public Message getFirstMessage(Severity severity)
Returns the first message with the given severity or null if none is found.
-
getMessageWithHighestSeverity
public Message getMessageWithHighestSeverity()
Returns the message with the highest severity. If there are multiple such messages, the first one is returned. If this listisEmpty(),nullis returned.
-
getMessageByCode
public Message getMessageByCode(java.lang.String code)
Returns the first message in the list that has the specified message code. Returnsnullif the list does not contain such a message.- Parameters:
code- the code to look for. May benull, as messages may havenullas their message code.
-
getMessagesByCode
public MessageList getMessagesByCode(java.lang.String code)
Returns a new message list containing all the message in this list that have the specified message code. Returns an empty list if this list does not contain any message with the given code.- Parameters:
code- the code to look for. May benull, as messages may havenullas their message code.
-
getMessagesBySeverity
public MessageList getMessagesBySeverity(Severity severity)
Returns a newMessageListcontaining only theMessages with the indicated severity. Returns an empty list if this list does not contain any message with the given severity.
-
getNoOfMessages
public int getNoOfMessages(Severity severity)
Returns the number of messages in this list that have the indicated severity.
-
getSubList
public MessageList getSubList(int maxCount)
The method returns a MethodList containing a sublist of messages of this messageList. By copying the content of this messageList, the original content won't be changed.maxCountdefines how big the sublist should be. IfmaxCountist higher than the size of the messageList the whole content of the original messageList will be returned.- Parameters:
maxCount- the number of messages to be returned- Returns:
- MessageList a sublist of the original MessageList
-
getMessagesByMarker
public MessageList getMessagesByMarker(IMarker marker)
-
getMessagesByMarker
@Deprecated public MessageList getMessagesByMarker(IPredicate<IMarker> markerPredicate)
Deprecated.for removal since 21.6; UsegetMessagesByMarker(Predicate)with the Java 8Predicateinstead.Returns a new message list containing all the message in this list with aIMarkerthe specifiedIPredicatematches. Returns an empty list if this list does not contain any such message.Sample usage:
messages.getMessagesByMarker(new IPredicate<IMarker>(){public boolean test(IMarker t){return t.isRequiredInformationMissing();}});Sample usage (Java8):
messages.getMessagesByMarker(IMarker::isRequiredInformationMissing);- Parameters:
markerPredicate- to match aIMarkerwith. Must not benull- Throws:
java.lang.NullPointerException- if markerPredicate isnull
-
getMessagesByMarker
public MessageList getMessagesByMarker(java.util.function.Predicate<IMarker> markerPredicate)
Returns a new message list containing all the message in this list with aIMarkerthe specifiedPredicatematches. Returns an empty list if this list does not contain any such message.Sample usage:
messages.getMessagesByMarker(IMarker::isRequiredInformationMissing);- Parameters:
markerPredicate- to match anIMarker. Must not benull- Throws:
java.lang.NullPointerException- if markerPredicate isnull
-
getSeverity
public Severity getSeverity()
Returns the message list's severity. This is the maximum severity of the list's messages. If the list does not contain any messages, the method returns 0.
-
getText
public java.lang.String getText()
Returns the text of all messages in the list, separated by the system's default line separator.
-
remove
public void remove(Message message)
Removes the given message from this message list.Does nothing if the given message is not actually contained in this message list.
- Parameters:
message- message to remove from this message list
-
containsErrorMsg
public boolean containsErrorMsg()
Returns true if one the messages in the list is an error message, otherwise false.
-
getMessagesFor
public MessageList getMessagesFor(java.lang.Object object)
Returns a new list with the messages in this list that belong to the given object (any property). Returns an empty list if no such message is found.
-
getMessagesFor
public MessageList getMessagesFor(java.lang.Object object, java.lang.String property)
Returns a new list with the messages in this list that belong to the given object and property. Returns an empty list if no such message is found.
-
getMessagesFor
public MessageList getMessagesFor(java.lang.Object object, java.lang.String property, int index)
Returns a new list with the messages in this list that belong to the given object and property and the property is of the given index. Returns an empty list if no such message is found.
-
wrapUpMessages
public void wrapUpMessages(java.lang.String messageCode)
Finds all the messages with the messageCodes at the messageList and merge the ObjectProperties from the same messageTexts together. After this, the messageList has only unique messageTexts inside.- Parameters:
messageCode- the messageCode to find
-
map
public MessageList map(java.util.function.UnaryOperator<Message> transformer)
Returns a new message list containing the same number of messages as this list, with the given transformer function applied to each message.
-
map
public MessageList map(java.util.function.Predicate<Message> shouldBeTransformed, java.util.function.UnaryOperator<Message> transformer)
Returns a new message list containing the same number of messages as this list, with the given transformer function applied to each message that matches the given predicate. All other messages are transferred to the new list without change.
-
iterator
public java.util.Iterator<Message> iterator()
Returns an iterator over the messages in this list.- Specified by:
iteratorin interfacejava.lang.Iterable<Message>
-
clear
public void clear()
Removes all of the messages from this list. This list will be empty after this call returns.
-
toString
public java.lang.String toString()
Returns all messages in the list separated by a line separator.- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
spliterator
public java.util.Spliterator<Message> spliterator()
Creates aSpliteratorover the included messages.- Specified by:
spliteratorin interfacejava.lang.Iterable<Message>- Since:
- 21.6
-
stream
public java.util.stream.Stream<Message> stream()
Returns a sequentialStreamof the included messages.- Since:
- 21.6
-
parallelStream
public java.util.stream.Stream<Message> parallelStream()
Returns a parallelStreamof the included messages.- Since:
- 21.6
-
-