Class 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 of Messages.
    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
      void add​(Message message)
      Adds the message to the list.
      void add​(MessageList messageList)
      Adds the messages in the given list to this list.
      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.
      void clear()
      Removes all of the messages from this list.
      boolean containsErrorMsg()
      Returns true if one the messages in the list is an error message, otherwise false.
      static 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.
      static 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.
      protected MessageList createEmptyMessageList()
      Creates a new empty message list.
      boolean equals​(java.lang.Object obj)  
      Message getFirstMessage​(Severity severity)
      Returns the first message with the given severity or null if none is found.
      Message getMessage​(int index)
      Returns the message at the indicated index (indexing starts with 0).
      Message getMessageByCode​(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.
      MessageList getMessagesByCode​(java.lang.String code)
      Returns a new message list containing all the message in this list that have the specified message code.
      MessageList getMessagesByMarker​(java.util.function.Predicate<IMarker> markerPredicate)
      Returns a new message list containing all the message in this list with a IMarker the specified Predicate matches.
      MessageList getMessagesByMarker​(IMarker marker)
      Returns a new message list containing all the message in this list that have the specified IMarker.
      MessageList getMessagesBySeverity​(Severity severity)
      Returns a new MessageList containing only the Messages with the indicated severity.
      MessageList getMessagesFor​(java.lang.Object object)
      Returns a new list with the messages in this list that belong to the given object (any property).
      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.
      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.
      Message getMessageWithHighestSeverity()
      Returns the message with the highest severity.
      int getNoOfMessages()
      Deprecated.
      for removal.
      int getNoOfMessages​(Severity severity)
      Returns the number of messages in this list that have the indicated severity.
      Severity getSeverity()
      Returns the message list's severity.
      MessageList getSubList​(int maxCount)
      The method returns a MethodList containing a sublist of messages of this messageList.
      java.lang.String getText()
      Returns the text of all messages in the list, separated by the system's default line separator.
      int hashCode()  
      boolean isEmpty()
      Returns true if the list is empty.
      java.util.Iterator<Message> iterator()
      Returns an iterator over the messages in this list.
      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.
      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.
      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 severity Message.ERROR with the given code, text and object properties and adds the message to the list.
      Message newError​(java.lang.String code, java.lang.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.
      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 severity Message.INFO with the given code, text and object properties and adds the message to the list.
      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 severity Message.WARNING with the given code, text and object properties and adds the message to the list.
      static MessageList of​(Message... messages)
      Returns a new MessageList that consists of the given Messages.
      static MessageList ofErrors​(java.lang.String... texts)
      Returns a new MessageList that contains error messages with the given texts.
      java.util.stream.Stream<Message> parallelStream()
      Returns a parallel Stream of the included messages.
      void remove​(Message message)
      Removes the given message from this message list.
      void setMessages​(java.util.List<Message> messages)
      Sets the message list.
      int size()
      Returns the total number of messages in the list.
      java.util.Spliterator<Message> spliterator()
      Creates a Spliterator over the included messages.
      java.util.stream.Stream<Message> stream()
      Returns a sequential Stream of the included messages.
      java.lang.String toString()
      Returns all messages in the list separated by a comma and a line separator.
      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.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

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

      • 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​(java.lang.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,
                                                   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 copy
        oldObject - 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 - 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​(java.lang.String code,
                                java.lang.String text,
                                java.lang.Object invalidObject,
                                java.lang.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​(java.lang.String code,
                                java.lang.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​(java.lang.String code,
                                  java.lang.String text,
                                  java.lang.Object invalidObject,
                                  java.lang.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​(java.lang.String code,
                               java.lang.String text,
                               java.lang.Object invalidObject,
                               java.lang.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:
        java.lang.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 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 list isEmpty(), null is returned.
      • getMessageByCode

        public Message getMessageByCode​(java.lang.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​(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 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​(java.util.function.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:
        java.lang.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 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:
        iterator in interface java.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 comma and a line separator.
        Overrides:
        toString in class java.lang.Object
      • hashCode

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

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • spliterator

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

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

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