Package org.faktorips.runtime
Class MessageList
java.lang.Object
org.faktorips.runtime.MessageList
- All Implemented Interfaces:
Serializable,Iterable<Message>
A list of
Messages.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty message list.MessageList(Message message) Creates a message list that contains the given message. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds 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.booleanReturns true if one the messages in the list is an error message, otherwise false.static final MessageListcreateCopy(MessageList list, Object oldObject, Object newObject) Creates a copy from the message list and replaces all references to the old object with the new object.static final MessageListcreateCopy(MessageList list, Map<ObjectProperty, ObjectProperty> objectPropertyMap) Creates a copy from the message list and replaces all references to the old object with the new object.protected MessageListCreates a new empty message list.booleangetFirstMessage(Severity severity) Returns the first message with the given severity or null if none is found.getMessage(int index) Returns the message at the indicated index (indexing starts with 0).getMessageByCode(String code) Returns the first message in the list that has the specified message code.Returns the message list.getMessagesByCode(String code) Returns a new message list containing all the message in this list that have the specified message code.getMessagesByMarker(Predicate<IMarker> markerPredicate) getMessagesByMarker(IMarker marker) Returns a new message list containing all the message in this list that have the specifiedIMarker.getMessagesBySeverity(Severity severity) Returns a newMessageListcontaining only theMessages with the indicated severity.getMessagesFor(Object object) Returns a new list with the messages in this list that belong to the given object (any property).getMessagesFor(Object object, String property) Returns a new list with the messages in this list that belong to the given object and property.getMessagesFor(Object object, 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 the message with the highest severity.intDeprecated.for removal.intgetNoOfMessages(Severity severity) Returns the number of messages in this list that have the indicated severity.Returns the message list's severity.getSubList(int maxCount) The method returns a MethodList containing a sublist of messages of this messageList.getText()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.iterator()Returns an iterator over the messages in this list.map(Predicate<Message> shouldBeTransformed, 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.map(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.Creates and returns a new message with severityMessage.ERRORwith the given code, text and object properties and adds the message to the list.newError(String code, 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.Creates and returns a new message with severityMessage.INFOwith the given code, text and object properties and adds the message to the list.newWarning(String code, String text, Object invalidObject, 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 final MessageListReturns a newMessageListthat consists of the givenMessages.static final MessageListReturns a newMessageListthat contains error messages with the given texts.Returns a parallelStreamof the included messages.voidRemoves the given message from this message list.voidsetMessages(List<Message> messages) Sets the message list.intsize()Returns the total number of messages in the list.Creates aSpliteratorover the included messages.stream()Returns a sequentialStreamof the included messages.toString()Returns all messages in the list separated by a comma and a line separator.voidwrapUpMessages(String messageCode) Finds all the messages with the messageCodes at the messageList and merge the ObjectProperties from the same messageTexts together.
-
Constructor Details
-
MessageList
public MessageList()Creates an empty message list. -
MessageList
Creates a message list that contains the given message.- Parameters:
message- the message to add. Ignored ifnull.
-
-
Method Details
-
createEmptyMessageList
Creates a new empty message list. -
of
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
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
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, 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
Adds the message to the list.- Parameters:
message- the message to add. Ignored ifnull.
-
add
Adds the messages in the given list to this list. -
add
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(String code, String text, Object invalidObject, 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
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(String code, String text, Object invalidObject, 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
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
Returns the message at the indicated index (indexing starts with 0).- Throws:
IndexOutOfBoundsException- if the index is out of range.
-
getNoOfMessages
Deprecated.for removal. Use #size() instead.Returns the number of messages in the list. -
getMessages
Returns the message list. -
setMessages
Sets the message list. -
getFirstMessage
Returns the first message with the given severity or null if none is found. -
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
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
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
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
Returns the number of messages in this list that have the indicated severity. -
getSubList
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
-
getMessagesByMarker
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:
NullPointerException- if markerPredicate isnull
-
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
Returns the text of all messages in the list, separated by the system's default line separator. -
remove
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
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
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
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
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
Returns a new message list containing the same number of messages as this list, with the given transformer function applied to each message. -
map
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
Returns an iterator over the messages in this list. -
clear
public void clear()Removes all of the messages from this list. This list will be empty after this call returns. -
toString
Returns all messages in the list separated by a comma and a line separator. -
hashCode
public int hashCode() -
equals
-
spliterator
Creates aSpliteratorover the included messages.- Specified by:
spliteratorin interfaceIterable<Message>- Since:
- 21.6
-
stream
Returns a sequentialStreamof the included messages.- Since:
- 21.6
-
parallelStream
Returns a parallelStreamof the included messages.- Since:
- 21.6
-