Class Messages
java.lang.Object
madkit.messages.Messages
This class provides utility methods for working with collections of messages.
- Since:
- MaDKit 6.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Object & Comparable<? super T>,
M extends ObjectMessage<T>>
ManyMessageWithMaxContent
(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.static <T extends Object & Comparable<? super T>,
M extends ObjectMessage<T>>
ManyMessageWithMinContent
(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.static <T extends Number,
M extends ObjectMessage<T>>
doubleaverageOnContent
(Collection<M> messages) Calculates the average of the contents of the given collection of messages.static <T,
M extends ObjectMessage<T>>
Map<T, List<M>> groupingByContent
(Collection<M> messages) Groups messages by their content.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.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.
-
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 messagesM
- 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 theComparable
interface. Furthermore, all elements must be mutually comparable (that is,e1.compareTo(e2)
must not throw aClassCastException
for any elementse1
ande2
in the collection).- Type Parameters:
T
- the type of the content of the messages, which must be comparableM
- 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 comparableNoSuchElementException
- 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 theComparable
interface. Furthermore, all elements must be mutually comparable (that is,e1.compareTo(e2)
must not throw aClassCastException
for any elementse1
ande2
in the collection).- Type Parameters:
T
- the type of the content of the messages, which must be comparableM
- 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 comparableNoSuchElementException
- 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 typeNumber
.- Type Parameters:
T
- the type of the content of the messages, which must be a numberM
- 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 theComparable
interface. Furthermore, all elements must be mutually comparable (that is,e1.compareTo(e2)
must not throw aClassCastException
for any elementse1
ande2
in the collection).- Type Parameters:
T
- the type of the content of the messages, which must be comparableM
- 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 comparableNoSuchElementException
- 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 theComparable
interface. Furthermore, all elements must be mutually comparable (that is,e1.compareTo(e2)
must not throw aClassCastException
for any elementse1
ande2
in the collection).- Type Parameters:
T
- the type of the content of the messages, which must be comparableM
- 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 comparableNoSuchElementException
- if the collection is empty- See Also:
-