madkit.message

## Class ObjectMessage<T>

- java.lang.Object
- - madkit.kernel.Message
  - - madkit.message.ObjectMessage<T>

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
  Direct Known Subclasses:
    BooleanMessage, EnumMessage, HookMessage, IntegerMessage, StringMessage

      public class ObjectMessage<T>
      extends Message

  This parameterizable class could be used to convey any Java Object between MaDKit agents.
  Since:
    MaDKit 5.0.0.1
  Version:
    0.9
  Author:
    Fabien Michel
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ObjectMessage(T content)` Builds a message with the specified content

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `T` | `getContent()` Gets the content of this message
    `static <T extends java.lang.Object & java.lang.Comparable<? super T>,M extends ObjectMessage<T>> M` | `max(java.util.Collection<M> messageCollection)` Returns the message containing the maximum element of the given collection, according to the natural ordering of the elements contained in the message.
    `static <T extends java.lang.Object & java.lang.Comparable<? super T>,M extends ObjectMessage<T>> M` | `min(java.util.Collection<M> messageCollection)` Returns the message containing the minimum element of the given collection, according to the natural ordering of the elements contained in the message.
    `static <T extends java.lang.Object & java.lang.Comparable<? super T>,M extends ObjectMessage<T>> void` | `sort(java.util.List<M> list)` Sorts the specified list of messages into ascending order, according to the natural ordering of the content of each message.
    `java.lang.String` | `toString()`

    - ### Methods inherited from class madkit.kernel.Message

      `clone, getConversationID, getReceiver, getSender`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ObjectMessage

          public ObjectMessage(T content)

      Builds a message with the specified content
      Parameters:
        `content` -

  - ### Method Detail

    - #### getContent

          public T getContent()

      Gets the content of this message
      Returns:
        the object of type T contained in the message

    - #### max

          public static <T extends java.lang.Object & java.lang.Comparable<? super T>,M extends ObjectMessage<T>> M max(java.util.Collection<M> messageCollection)

      Returns the 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).

      This method iterates over the entire collection, hence it requires time proportional to the size of the collection.

      Parameters:
        `messageCollection` - the collection of messages whose maximum element is to be determined.
      Returns:
        the message containing the maximum element.
      Throws:
        `java.lang.ClassCastException` - if the content of the messages are not mutually comparable.
        `java.util.NoSuchElementException` - if the collection is empty.
      See Also:
        `Comparable`

    - #### min

          public static <T extends java.lang.Object & java.lang.Comparable<? super T>,M extends ObjectMessage<T>> M min(java.util.Collection<M> messageCollection)

      Returns the 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).

      This method iterates over the entire collection, hence it requires time proportional to the size of the collection.

      Parameters:
        `messageCollection` - the collection of messages whose maximum element is to be determined.
      Returns:
        the message containing the minimum element.
      Throws:
        `java.lang.ClassCastException` - if the content of the messages are not mutually comparable.
        `java.util.NoSuchElementException` - if the collection is empty.
      See Also:
        `Comparable`

    - #### sort

          public static <T extends java.lang.Object & java.lang.Comparable<? super T>,M extends ObjectMessage<T>> void sort(java.util.List<M> list)

      Sorts the specified list of messages into ascending order, according to the natural ordering of the content of each message. All elements contained in the messages must implement the `Comparable` interface. Furthermore, all these elements must be mutually comparable (that is, `e1.compareTo(e2)` must not throw a `ClassCastException` for any elements `e1` and `e2` in the list).

      This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.

      The specified list must be modifiable, but need not be resizable.

      Parameters:
        `list` - the list to be sorted.
      Throws:
        `java.lang.ClassCastException` - if the list contains elements that are not mutually comparable (for example, strings and integers).
        `java.lang.UnsupportedOperationException` - if the specified list's list-iterator does not support the `set` operation.
        `java.lang.IllegalArgumentException` - (optional) if the implementation detects that the natural ordering of the list elements is found to violate the `Comparable` contract

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `Message`
      See Also:
        `Message.toString()`

Fabien Michel, Olivier Gutknecht, Jacques Ferber - November 18 2014