de.caff.generics

## Class OrderedPair<S,T>

- java.lang.Object
- - de.caff.generics.OrderedPair<S,T>

- Type Parameters:
    `S` - type of first entry
    `T` - type of second entry
  All Implemented Interfaces:
    ITuple2<S,T>, java.util.Map.Entry<S,T>
  Direct Known Subclasses:
    Pair

      public class OrderedPair<S,T>
      extends java.lang.Object
      implements java.util.Map.Entry<S,T>, ITuple2<S,T>

  A simple ordered pair.

  Useful for temporary packing.

  It implements also `Map.Entry`, and will return the first value as key and the second value as value. Obviously it will not allow setting to the underlying map.

  Author:
    Rammi

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface de.caff.generics.tuple.ITuple2

      `ITuple2.Base<T1,T2>`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `S` | `first` The first element.
    `T` | `second` The second element.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `OrderedPair(S first, T second)` Constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `S` | `_1()` Get the first element.
    `T` | `_2()` Get the second element.
    `static <U,V> OrderedPair<U,V>` | `create(java.util.Map.Entry<U,V> mapEntry)` Create an ordered pair from a map entry.
    `static <U,V> OrderedPair<U,V>` | `create(U firstValue, V secondValue)` Create an ordered pair from two values.
    `boolean` | `equals(java.lang.Object o)` Is this pair equal to another?
    `static <U extends java.lang.Comparable<U>,V> java.util.Comparator<OrderedPair<U,V>>` | `getFirstEntryOrderedPairComparator()` Get a comparator which compares the first entries of ordered pairs using their natural order.
    `static <U,V> java.util.Comparator<OrderedPair<U,V>>` | `getFirstEntryOrderedPairComparator(java.util.Comparator<U> comparator)` Get a comparator which compares the first entries of ordered pairs using a comparator.
    `S` | `getKey()` Returns the key corresponding to this entry.
    `static <U,V extends java.lang.Comparable<V>> java.util.Comparator<OrderedPair<U,V>>` | `getSecondEntryOrderedPairComparator()` Get a comparator which compares the second entries of ordered pairs using their natural order.
    `static <U,V> java.util.Comparator<OrderedPair<U,V>>` | `getSecondEntryOrderedPairComparator(java.util.Comparator<V> comparator)` Get a comparator which compares the second entries of ordered pairs using a comparator.
    `T` | `getValue()` Returns the value corresponding to this entry.
    `int` | `hashCode()` Get a hash code.
    `T` | `setValue(T value)` Replaces the value corresponding to this entry with the specified value (optional operation).
    `OrderedPair<T,S>` | `swapped()` Get a ordered pair with inverted order.
    `java.lang.String` | `toString()`

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.Map.Entry

      `comparingByKey, comparingByKey, comparingByValue, comparingByValue`

    - ### Methods inherited from interface de.caff.generics.tuple.ITuple2

      `_21, asBase, concat1, concat2, concat3, concat4, concat5, concat6, concat7, concat8, concatPred1, concatPred2, concatPred3, concatPred4, concatPred5, concatPred6, concatPred7, concatPred8, concatProc1, concatProc2, concatProc3, concatProc4, concatProc5, concatProc6, concatProc7, concatProc8, equals, frozen, frozenNotNull, hash, invoke, sendTo, testBy, toString, toString, view`

- - ### Field Detail

    - #### first

          public S first

      The first element.

    - #### second

          public T second

      The second element.

  - ### Constructor Detail

    - #### OrderedPair

          public OrderedPair(S first,
                             T second)

      Constructor.
      Parameters:
        `first` - first element of the pair
        `second` - second element of the pair

  - ### Method Detail

    - #### getKey

          public S getKey()

      Returns the key corresponding to this entry.
      Specified by:
        `getKey` in interface `java.util.Map.Entry<S,T>`
      Returns:
        the key corresponding to this entry.
      Throws:
        `java.lang.IllegalStateException` - implementations may, but are not required to, throw this exception if the entry has been removed from the backing map

    - #### getValue

          public T getValue()

      Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's `remove` operation), the results of this call are undefined.
      Specified by:
        `getValue` in interface `java.util.Map.Entry<S,T>`
      Returns:
        the value corresponding to this entry.
      Throws:
        `java.lang.IllegalStateException` - implementations may, but are not required to, throw this exception if the entry has been removed from the backing map

    - #### setValue

          public T setValue(T value)

      Replaces the value corresponding to this entry with the specified value (optional operation). (Writes through to the map.) The behavior of this call is undefined if the mapping has already been removed from the map (by the iterator's `remove` operation).
      Specified by:
        `setValue` in interface `java.util.Map.Entry<S,T>`
      Parameters:
        `value` - new value to be stored in this entry.
      Returns:
        old value corresponding to the entry.
      Throws:
        `java.lang.UnsupportedOperationException` - if the `put` operation is not supported by the backing map.
        `java.lang.ClassCastException` - if the class of the specified value prevents it from being stored in the backing map.
        `java.lang.IllegalArgumentException` - if some aspect of this value prevents it from being stored in the backing map.
        `java.lang.NullPointerException` - if the backing map does not permit `null` values, and the specified value is `null`.
        `java.lang.IllegalStateException` - implementations may, but are not required to, throw this exception if the entry has been removed from the backing map

    - #### _1

          public S _1()

      Description copied from interface: `ITuple2`
      Get the first element.
      Specified by:
        `_1` in interface `ITuple2<S,T>`
      Returns:
        first element

    - #### _2

          public T _2()

      Description copied from interface: `ITuple2`
      Get the second element.
      Specified by:
        `_2` in interface `ITuple2<S,T>`
      Returns:
        second element

    - #### equals

          public boolean equals(java.lang.Object o)

      Is this pair equal to another? This just checks whether both first and second are equal in each pair.
      Specified by:
        `equals` in interface `java.util.Map.Entry<S,T>`
      Overrides:
        `equals` in class `java.lang.Object`
      Parameters:
        `o` - other pair
      Returns:
        `true` if both elements are equal
        `false` otherwise

    - #### hashCode

          public int hashCode()

      Get a hash code.
      Specified by:
        `hashCode` in interface `java.util.Map.Entry<S,T>`
      Overrides:
        `hashCode` in class `java.lang.Object`
      Returns:
        hash code

    - #### swapped

          @NotNull
          public OrderedPair<T,S> swapped()

      Get a ordered pair with inverted order.
      Returns:
        pair with swapped `first` and `second` entries

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### getFirstEntryOrderedPairComparator

          @NotNull
          public static <U extends java.lang.Comparable<U>,V> java.util.Comparator<OrderedPair<U,V>> getFirstEntryOrderedPairComparator()

      Get a comparator which compares the first entries of ordered pairs using their natural order.
      Type Parameters:
        `U` - first entry type
        `V` - second entry type
      Returns:
        comparator for ordered pairs, comparing the first entry

    - #### getFirstEntryOrderedPairComparator

          @NotNull
          public static <U,V> java.util.Comparator<OrderedPair<U,V>> getFirstEntryOrderedPairComparator(java.util.Comparator<U> comparator)

      Get a comparator which compares the first entries of ordered pairs using a comparator.
      Type Parameters:
        `U` - first entry type
        `V` - second entry type
      Parameters:
        `comparator` - comparator for first entry
      Returns:
        comparator for ordered pairs, comparing the first entry

    - #### getSecondEntryOrderedPairComparator

          @NotNull
          public static <U,V extends java.lang.Comparable<V>> java.util.Comparator<OrderedPair<U,V>> getSecondEntryOrderedPairComparator()

      Get a comparator which compares the second entries of ordered pairs using their natural order.
      Type Parameters:
        `U` - first entry type
        `V` - second entry type
      Returns:
        comparator for ordered pairs, comparing the second entry

    - #### getSecondEntryOrderedPairComparator

          @NotNull
          public static <U,V> java.util.Comparator<OrderedPair<U,V>> getSecondEntryOrderedPairComparator(java.util.Comparator<V> comparator)

      Get a comparator which compares the second entries of ordered pairs using a comparator.
      Type Parameters:
        `U` - first entry type
        `V` - second entry type
      Parameters:
        `comparator` - comparator for first entry
      Returns:
        comparator for ordered pairs, comparing the first entry

    - #### create

          @NotNull
          public static <U,V> OrderedPair<U,V> create(U firstValue,
                                                               V secondValue)

      Create an ordered pair from two values.
      Type Parameters:
        `U` - first value type
        `V` - second value type
      Parameters:
        `firstValue` - first value
        `secondValue` - second value
      Returns:
        ordered pair

    - #### create

          @NotNull
          public static <U,V> OrderedPair<U,V> create(java.util.Map.Entry<U,V> mapEntry)

      Create an ordered pair from a map entry.
      Type Parameters:
        `U` - first value (map key) type
        `V` - second value (map value) type
      Parameters:
        `mapEntry` - map entry
      Returns:
        ordered pair