Class Messages

java.lang.Object
madkit.messages.Messages

public class Messages extends Object
This class provides utility methods for working with collections of messages.
Since:
MaDKit 6.0
  • Method Details

    • groupingByContent

      public static <T, M extends ObjectMessage<T>> Map<T,List<M>> groupingByContent(Collection<M> messages)
      Groups messages by their content.
      Type Parameters:
      T - the type of the content of the messages
      M - the type of the messages
      Parameters:
      messages - the collection of messages to be grouped
      Returns:
      a map where the keys are the message contents and the values are lists of messages with that content
    • messagesWithMaxContent

      public static <T extends Object & Comparable<? super T>, M extends ObjectMessage<T>> List<M> messagesWithMaxContent(Collection<M> messages)
      Returns the messages containing the maximum element of the given collection, according to the natural ordering of the elements contained in the message. All elements in the messages must implement the Comparable interface. Furthermore, all elements must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the collection).
      Type Parameters:
      T - the type of the content of the messages, which must be comparable
      M - the type of the messages
      Parameters:
      messages - the collection of messages whose maximum element is to be determined
      Returns:
      the list of messages containing the maximum element
      Throws:
      ClassCastException - if the content of the messages are not mutually comparable
      NoSuchElementException - if the collection is empty
      See Also:
    • messagesWithMinContent

      public static <T extends Object & Comparable<? super T>, M extends ObjectMessage<T>> List<M> messagesWithMinContent(Collection<M> messages)
      Returns the messages containing the minimum element of the given collection, according to the natural ordering of the elements contained in the message. All elements in the messages must implement the Comparable interface. Furthermore, all elements must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the collection).
      Type Parameters:
      T - the type of the content of the messages, which must be comparable
      M - the type of the messages
      Parameters:
      messages - the collection of messages whose minimum element is to be determined
      Returns:
      the list of messages containing the minimum element
      Throws:
      ClassCastException - if the content of the messages are not mutually comparable
      NoSuchElementException - if the collection is empty
      See Also:
    • averageOnContent

      public static <T extends Number, M extends ObjectMessage<T>> double averageOnContent(Collection<M> messages)
      Calculates the average of the contents of the given collection of messages. The content of the messages must be of type Number.
      Type Parameters:
      T - the type of the content of the messages, which must be a number
      M - the type of the messages
      Parameters:
      messages - the collection of messages whose content average is to be calculated
      Returns:
      the average of the contents of the messages
    • anyMessageWithMaxContent

      public static <T extends Object & Comparable<? super T>, M extends ObjectMessage<T>> M anyMessageWithMaxContent(Collection<M> messages)
      Returns any message containing the maximum element of the given collection, according to the natural ordering of the elements contained in the message. All elements in the messages must implement the Comparable interface. Furthermore, all elements must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the collection).
      Type Parameters:
      T - the type of the content of the messages, which must be comparable
      M - the type of the messages
      Parameters:
      messages - the collection of messages whose maximum element is to be determined
      Returns:
      any message containing the maximum element, or null if the collection is empty
      Throws:
      ClassCastException - if the content of the messages are not mutually comparable
      NoSuchElementException - if the collection is empty
      See Also:
    • anyMessageWithMinContent

      public static <T extends Object & Comparable<? super T>, M extends ObjectMessage<T>> M anyMessageWithMinContent(Collection<M> messages)
      Returns any message containing the minimum element of the given collection, according to the natural ordering of the elements contained in the message. All elements in the messages must implement the Comparable interface. Furthermore, all elements must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the collection).
      Type Parameters:
      T - the type of the content of the messages, which must be comparable
      M - the type of the messages
      Parameters:
      messages - the collection of messages whose minimum element is to be determined
      Returns:
      any message containing the minimum element, or null if the collection is empty
      Throws:
      ClassCastException - if the content of the messages are not mutually comparable
      NoSuchElementException - if the collection is empty
      See Also: