Class MessageList

java.lang.Object
org.faktorips.runtime.MessageList
All Implemented Interfaces:
Serializable, Iterable<Message>

public class MessageList extends Object implements Serializable, Iterable<Message>
A list of Messages.
See Also:
  • Constructor Details

    • 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 if null.
  • Method Details

    • createEmptyMessageList

      protected MessageList createEmptyMessageList()
      Creates a new empty message list.
    • of

      public static final MessageList of(Message... messages)
      Returns a new MessageList that consists of the given Messages. Returns an empty MessageList if null is given.
      Parameters:
      messages - the Messages that the new MessageList will contain. May be null
      Returns:
      a new MessageList that consist of the given Messages
    • ofErrors

      public static final MessageList ofErrors(String... texts)
      Returns a new MessageList that contains error messages with the given texts. Returns an empty MessageList if null or an empty array is given.
      Parameters:
      texts - the texts of the error messages in the new MessageList. May be null or empty
      Returns:
      a new MessageList that contains error messages with the given texts or an empty MessageList
    • createCopy

      public static final MessageList createCopy(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.
      Parameters:
      list - the list to copy
      oldObject - 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 - The Map between old and new ObjectProperty
      Returns:
      MessageList
    • add

      public void add(Message message)
      Adds the message to the list.
      Parameters:
      message - the message to add. Ignored if null.
    • 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 - true if the invalidObjectProperty should be set in all messages. false if 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 severity Message.ERROR with the given code, text and object properties and adds the message to the list.
    • newError

      public Message newError(String code, String text, ObjectProperty... invalidObjectProperty)
      Creates and returns a new message with severity Message.ERROR with 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 severity Message.WARNING with the given code, text and object properties and adds the message to the list.
    • newInfo

      public Message newInfo(String code, String text, Object invalidObject, String invalidProperty)
      Creates and returns a new message with severity Message.INFO with 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:
      IndexOutOfBoundsException - if the index is out of range.
    • getNoOfMessages

      @Deprecated public int getNoOfMessages()
      Deprecated.
      for removal. Use #size() instead.
      Returns the number of messages in the list.
    • getMessages

      public List<Message> getMessages()
      Returns the message list.
    • setMessages

      public void setMessages(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 list isEmpty(), null is returned.
    • getMessageByCode

      public Message getMessageByCode(String code)
      Returns the first message in the list that has the specified message code. Returns null if the list does not contain such a message.
      Parameters:
      code - the code to look for. May be null, as messages may have null as their message code.
    • getMessagesByCode

      public MessageList getMessagesByCode(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 be null, as messages may have null as their message code.
    • getMessagesBySeverity

      public MessageList getMessagesBySeverity(Severity severity)
      Returns a new MessageList containing only the Messages 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. maxCount defines how big the sublist should be. If maxCount ist 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)
      Returns a new message list containing all the message in this list that have the specified IMarker. Returns an empty list if this list does not contain any message with the given IMarker.
      Parameters:
      marker - the IMarker to look for. If null, all messages without a IMarker are returned.
    • getMessagesByMarker

      public MessageList getMessagesByMarker(Predicate<IMarker> markerPredicate)
      Returns a new message list containing all the message in this list with a IMarker the specified Predicate matches. Returns an empty list if this list does not contain any such message.

      Sample usage: messages.getMessagesByMarker(IMarker::isRequiredInformationMissing);

      Parameters:
      markerPredicate - to match an IMarker. Must not be null
      Throws:
      NullPointerException - if markerPredicate is null
    • 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 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(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(Object object, 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(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 an empty list if no such message is found.
    • wrapUpMessages

      public void wrapUpMessages(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(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(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. All other messages are transferred to the new list without change.
    • iterator

      public Iterator<Message> iterator()
      Returns an iterator over the messages in this list.
      Specified by:
      iterator in interface 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 String toString()
      Returns all messages in the list separated by a comma and a line separator.
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • spliterator

      public Spliterator<Message> spliterator()
      Creates a Spliterator over the included messages.
      Specified by:
      spliterator in interface Iterable<Message>
      Since:
      21.6
    • stream

      public Stream<Message> stream()
      Returns a sequential Stream of the included messages.
      Since:
      21.6
    • parallelStream

      public Stream<Message> parallelStream()
      Returns a parallel Stream of the included messages.
      Since:
      21.6