de.caff.generics

## Class LongPair

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

- All Implemented Interfaces:
    LongIndexable, PrimitiveLongIterable, Sizeable, java.io.Serializable, java.lang.Iterable<java.lang.Long>

      public final class LongPair
      extends java.lang.Object
      implements java.io.Serializable, LongIndexable

  A pair of primitive long values.

  This is similar to `Pair`, but for raw `long` 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.LongIndexable

      `LongIndexable.Base, LongIndexable.LongIndexableSpliterator`

  - ### Field Summary

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

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

      `EMPTY`

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

      `EMPTY_LONG_ITERATOR`

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

      `NULL`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LongPair(long first, long second)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T> T` | `applyAsLongs(LongFunction2<T> function)` Apply a 2-long function on this pair.
    `boolean` | `equals(java.lang.Object o)`
    `long` | `get(int index)` Get the element at the given index.
    `int` | `hashCode()`
    `long` | `operate(LongOperator2 operator)` Call an 2-long operator on this pair.
    `int` | `size()` Get the size.
    `LongPair` | `swapped()` Get this pair with swapped values.
    `boolean` | `test(LongPredicate2 predicate)` Call a 2-long predicate on this pair.
    `java.lang.String` | `toString()`
    `Tuple2<java.lang.Long,java.lang.Long>` | `toTuple()` Convert this into a tuple.
    `LongPair` | `withFirst(long first)` Get this pair with a different first value.
    `LongPair` | `withSecond(long 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.LongIndexable

      `addAllTo, addToArray, addToArray, asBase, asCollection, asIndexable, asList, binarySearch, binarySearch, compare, compareUnsigned, emptyIndexable, equal, equal, firstMatch, foldLeft, frozen, frozenLongSpliterator, getMod, gyt, hash, headSet, indexes, init, initByIndex, intIndexes, isEmpty, isOrdered, isStrictlyOrdered, iterator, lastMatch, listIterator, longIterator, longIterator, longSpliterator, nextMatch, ordered, ordered, previousMatch, reverse, rotated, singleton, subSet, sybSet, tailSet, toArray, toList, toString, view, viewArray, viewArray, viewArray, viewAsBoolean, viewAsByte, viewAsDouble, viewAsDouble, viewAsFloat, viewAsInt, viewAsInt, viewAsShort, viewByIndex, viewIndexable, viewIndexable, viewIndexable, viewList, viewList, viewList, viewNumberArray, viewOp, withAppendedValue, withCachedHash, withExchangedValueAt, withInsertedValueAt, withRemovedValueAt, withSwappedValuesAt`

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

      `average, containsLong, forEachLong, forEachLongFragile, spliterator, stream, sum, sumX`

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

      `forEach`

- - ### Field Detail

    - #### first

          public final long first

      The first value of this pair.

    - #### second

          public final long second

      The second value of this pair.

  - ### Constructor Detail

    - #### LongPair

          public LongPair(long first,
                          long second)

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

  - ### Method Detail

    - #### withFirst

          @NotNull
          public LongPair withFirst(long 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 LongPair withSecond(long 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 LongPair 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 long get(int index)

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

    - #### applyAsLongs

          public <T> T applyAsLongs(@NotNull
                                    LongFunction2<T> function)

      Apply a 2-long 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 long operate(@NotNull
                              LongOperator2 operator)

      Call an 2-long 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
                              LongPredicate2 predicate)

      Call a 2-long 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.Long,java.lang.Long> 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`