de.caff.generics

## Class CharPair

- java.lang.Object
- - de.caff.generics.CharPair

- All Implemented Interfaces:
    CharIndexable, PrimitiveCharIterable, Sizeable, java.io.Serializable, java.lang.Iterable<java.lang.Character>

      public final class CharPair
      extends java.lang.Object
      implements java.io.Serializable, CharIndexable

  A pair of primitive char values.

  This is similar to `Pair`, but for raw `char` values. As these values are defined final, this class is also immutable.

  Since:
    December 04, 2020
  Author:
    Rammi
  See Also:
    Serialized Form

- - ### Nested Class Summary

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

      `CharIndexable.Base`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `char` | `first` The first value of this pair.
    `char` | `second` The second value of this pair.

    - ### Fields inherited from interface de.caff.generics.CharIndexable

      `EMPTY`

    - ### Fields inherited from interface de.caff.generics.PrimitiveCharIterable

      `EMPTY_CHAR_ITERATOR`

    - ### Fields inherited from interface de.caff.generics.Sizeable

      `NULL`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CharPair(char first, char second)` Constructor.
    `CharPair(java.lang.String pair)` Create a character pair from a 2-character string.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T> T` | `applyAsChars(CharFunction2<T> function)` Apply a 2-character function on this pair.
    `boolean` | `equals(java.lang.Object o)`
    `char` | `get(int index)` Get the element at the given index.
    `int` | `hashCode()`
    `char` | `operate(CharOperator2 operator)` Call an 2-character operator on this pair.
    `int` | `size()` Get the size.
    `CharPair` | `swapped()` Get this pair with swapped values.
    `boolean` | `test(CharPredicate2 predicate)` Call a 2-character predicate on this pair.
    `IntPair` | `toIntPair()` Convert this char pair into an integer pair.
    `java.lang.String` | `toString()`
    `Tuple2<java.lang.Character,java.lang.Character>` | `toTuple()` Convert this into a tuple.
    `CharPair` | `withFirst(char first)` Get this pair with a different first value.
    `CharPair` | `withSecond(char second)` Get this pair with a different first value.

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

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

    - ### Methods inherited from interface de.caff.generics.CharIndexable

      `addAllTo, addToArray, addToArray, addToArray, addToArray, asBase, asCharSequence, asCollection, asIndexable, asIntIndexable, asList, binarySearch, binarySearch, charIterator, charIterator, compare, emptyIndexable, equal, equal, firstMatch, foldLeft, frozen, getMod, gyt, hash, headSet, indexes, init, initByIndex, intIndexes, intIterator, isEmpty, isOrdered, isOrdered, isStrictlyOrdered, isStrictlyOrdered, iterator, lastMatch, listIterator, makeString, nextMatch, ordered, previousMatch, reverse, rotated, singleton, subSet, sybSet, tailSet, toArray, toIntArray, toList, toString, toText, view, viewArray, viewArray, viewArray, viewAsBoolean, viewAsCharSequence, viewByIndex, viewChars, viewIndexable, viewIndexable, viewIndexable, viewList, viewList, viewList, viewOp, viewString, withAppendedValue, withExchangedValueAt, withInsertedValueAt, withRemovedValueAt, withSwappedValuesAt`

    - ### Methods inherited from interface de.caff.generics.PrimitiveCharIterable

      `asIntIterable, asLongIterable, containsChar, forEachChar, forEachCharFragile`

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

      `forEach, spliterator`

- - ### Field Detail

    - #### first

          public final char first

      The first value of this pair.

    - #### second

          public final char second

      The second value of this pair.

  - ### Constructor Detail

    - #### CharPair

          public CharPair(char first,
                          char second)

      Constructor.
      Parameters:
        `first` - first value of pair
        `second` - second value of pair

    - #### CharPair

          public CharPair(@NotNull
                          java.lang.String pair)

      Create a character pair from a 2-character string.
      Parameters:
        `pair` - string with 2 characters
      Throws:
        `java.lang.IllegalArgumentException` - if string does not have 2 characters

  - ### Method Detail

    - #### toIntPair

          @NotNull
          public IntPair toIntPair()

      Convert this char pair into an integer pair.
      Returns:
        integer pair with same values

    - #### withFirst

          @NotNull
          public CharPair withFirst(char first)

      Get this pair with a different first value.
      Parameters:
        `first` - new first value
      Returns:
        pair with the given `first` value, and the `second` value of this pair

    - #### withSecond

          @NotNull
          public CharPair withSecond(char second)

      Get this pair with a different first value.
      Parameters:
        `second` - new second value
      Returns:
        pair with the `first` value of this pair, and the given `second` value

    - #### swapped

          @NotNull
          public CharPair swapped()

      Get this pair with swapped values.
      Returns:
        pair with swapped `first` and `second` values

    - #### size

          public int size()

      Description copied from interface: `Sizeable`
      Get the size. Size is never negative.
      Specified by:
        `size` in interface `Sizeable`
      Returns:
        the size of this object, usually the number of contained elements, must not be negative

    - #### get

          public char get(int index)

      Description copied from interface: `CharIndexable`
      Get the element at the given index.
      Specified by:
        `get` in interface `CharIndexable`
      Parameters:
        `index` - index between `0` and `size() - 1`
      Returns:
        element at the given index

    - #### applyAsChars

          public <T> T applyAsChars(@NotNull
                                    CharFunction2<T> function)

      Apply a 2-character function on this pair.
      Type Parameters:
        `T` - output type
      Parameters:
        `function` - function to apply, `first` becomes its first, `second` its second argument
      Returns:
        result of applying the function

    - #### operate

          public char operate(@NotNull
                              CharOperator2 operator)

      Call an 2-character operator on this pair.
      Parameters:
        `operator` - operator to apply, `first` becomes its first, `second` its second argument
      Returns:
        result of applying the operator

    - #### test

          public boolean test(@NotNull
                              CharPredicate2 predicate)

      Call a 2-character predicate on this pair.
      Parameters:
        `predicate` - predicate to apply, `first` becomes its first, `second` its second argument
      Returns:
        result of testing this pair

    - #### toTuple

          @NotNull
          public Tuple2<java.lang.Character,java.lang.Character> toTuple()

      Convert this into a tuple.
      Returns:
        tuple created from this pair

    - #### equals

          public boolean equals(java.lang.Object o)

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

    - #### hashCode

          public int hashCode()

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

    - #### toString

          @NotNull
          public java.lang.String toString()

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