de.caff.generics

## Class Pair<T>

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

- All Implemented Interfaces:
    ITuple2<T,T>, java.lang.Iterable<T>, java.util.Map.Entry<T,T>

      public class Pair<T>
      extends OrderedPair<T,T>
      implements java.lang.Iterable<T>

  An ordered pair with equal types for first and second.
  Author:
    Rammi

- - ### Nested Class Summary

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

      `ITuple2.Base<T1,T2>`

  - ### Field Summary

    - ### Fields inherited from class de.caff.generics.OrderedPair

      `first, second`

  - ### Constructor Summary

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

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <U> Pair<U>` | `createPair(U f, U s)` Create a pair from two items.
    `T` | `get(int index)` Get the first or second parameter via its index.
    `static <S extends java.lang.Comparable<S>> java.util.Comparator<Pair<S>>` | `getFirstEntryPairComparator()` Get a comparator which compares the first entries of pairs using their natural order.
    `static <S> java.util.Comparator<Pair<S>>` | `getFirstEntryPairComparator(java.util.Comparator<S> comparator)` Get a comparator which compares the first entries of pairs using a comparator.
    `static <S extends java.lang.Comparable<S>> java.util.Comparator<Pair<S>>` | `getFirstThanSecondEntryPairComparator()` Get a comparator which compares the first entries of two pairs using their natural order., and then the second entries of the pairs if the first are equal.
    `static <S> java.util.Comparator<Pair<S>>` | `getFirstThanSecondEntryPairComparator(java.util.Comparator<S> comparator)` Get a comparator which compares the first entries of two pairs, and then the second entries of the pairs if the first are equal.
    `static <S extends java.lang.Comparable<S>> java.util.Comparator<Pair<S>>` | `getSecondEntryPairComparator()` Get a comparator which compares the first entries of pairs using their natural order.
    `static <S> java.util.Comparator<Pair<S>>` | `getSecondEntryPairComparator(java.util.Comparator<S> comparator)` Get a comparator which compares the second entries of pairs using a comparator.
    `java.util.Iterator<T>` | `iterator()` Returns an iterator over this pair.
    `(package private) void` | `orderBy(Ordering<? super T> ordering)` Order the elements in this pair.
    `void` | `set(int index, T item)` Set the first or second parameter via its index.
    `void` | `swap()` Exchange first and second.

    - ### Methods inherited from class de.caff.generics.OrderedPair

      `_1, _2, create, create, equals, getFirstEntryOrderedPairComparator, getFirstEntryOrderedPairComparator, getKey, getSecondEntryOrderedPairComparator, getSecondEntryOrderedPairComparator, getValue, hashCode, setValue, swapped, toString`

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

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

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

    - ### 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`

- - ### Constructor Detail

    - #### Pair

          public Pair(T first,
                      T second)

      Constructor.
      Parameters:
        `first` - first entry
        `second` - second entry

  - ### Method Detail

    - #### orderBy

          void orderBy(@NotNull
                       Ordering<? super T> ordering)

      Order the elements in this pair.
      Parameters:
        `ordering` - ordering to apply

    - #### iterator

          @NotNull
          public java.util.Iterator<T> iterator()

      Returns an iterator over this pair.
      Specified by:
        `iterator` in interface `java.lang.Iterable<T>`
      Returns:
        an Iterator.

    - #### swap

          public void swap()

      Exchange first and second.

    - #### get

          public T get(int index)

      Get the first or second parameter via its index. This can come handy in special situations.
      Parameters:
        `index` - either `0` or `1`
      Returns:
        if `index` is `0` the first entry, if `index` is `1` the second entry

    - #### set

          public void set(int index,
                          T item)

      Set the first or second parameter via its index. This can come handy in special situations
      Parameters:
        `index` - either `0` or `1`
        `item` - new first if `index` is `0`, new second if `index` is `1`

    - #### getFirstEntryPairComparator

          public static <S extends java.lang.Comparable<S>> java.util.Comparator<Pair<S>> getFirstEntryPairComparator()

      Get a comparator which compares the first entries of pairs using their natural order.
      Type Parameters:
        `S` - pair entry type (comparable)
      Returns:
        comparator for ordered pairs, comparing the first entry

    - #### getFirstEntryPairComparator

          @NotNull
          public static <S> java.util.Comparator<Pair<S>> getFirstEntryPairComparator(@NotNull
                                                                                               java.util.Comparator<S> comparator)

      Get a comparator which compares the first entries of pairs using a comparator.
      Type Parameters:
        `S` - pair entry type
      Parameters:
        `comparator` - comparator for inner elements
      Returns:
        comparator for ordered pairs, comparing the first entry

    - #### getSecondEntryPairComparator

          @NotNull
          public static <S extends java.lang.Comparable<S>> java.util.Comparator<Pair<S>> getSecondEntryPairComparator()

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

    - #### getSecondEntryPairComparator

          @NotNull
          public static <S> java.util.Comparator<Pair<S>> getSecondEntryPairComparator(@NotNull
                                                                                                java.util.Comparator<S> comparator)

      Get a comparator which compares the second entries of pairs using a comparator.
      Type Parameters:
        `S` - pair entry type
      Parameters:
        `comparator` - comparator for inner elements
      Returns:
        comparator for ordered pairs, comparing the second entry

    - #### getFirstThanSecondEntryPairComparator

          @NotNull
          public static <S extends java.lang.Comparable<S>> java.util.Comparator<Pair<S>> getFirstThanSecondEntryPairComparator()

      Get a comparator which compares the first entries of two pairs using their natural order., and then the second entries of the pairs if the first are equal.
      Type Parameters:
        `S` - pair entry type (comparable)
      Returns:
        comparator for ordered pairs, comparing both entries in order

    - #### getFirstThanSecondEntryPairComparator

          @NotNull
          public static <S> java.util.Comparator<Pair<S>> getFirstThanSecondEntryPairComparator(@NotNull
                                                                                                         java.util.Comparator<S> comparator)

      Get a comparator which compares the first entries of two pairs, and then the second entries of the pairs if the first are equal.
      Type Parameters:
        `S` - pair entry type (comparable)
      Parameters:
        `comparator` - comparator for inner elements
      Returns:
        comparator for ordered pairs, comparing both entries in order

    - #### createPair

          @NotNull
          public static <U> Pair<U> createPair(U f,
                                                        U s)

      Create a pair from two items.
      Type Parameters:
        `U` - item type
      Parameters:
        `f` - first item
        `s` - second item
      Returns:
        pair of items