All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mmnaseri.utils.tuples.impl.TenTuple Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
package com.mmnaseri.utils.tuples.impl;

import com.mmnaseri.utils.tuples.facade.HasEighth;
import com.mmnaseri.utils.tuples.facade.HasFifth;
import com.mmnaseri.utils.tuples.facade.HasFirst;
import com.mmnaseri.utils.tuples.facade.HasFourth;
import com.mmnaseri.utils.tuples.facade.HasNinth;
import com.mmnaseri.utils.tuples.facade.HasSecond;
import com.mmnaseri.utils.tuples.facade.HasSeventh;
import com.mmnaseri.utils.tuples.facade.HasSixth;
import com.mmnaseri.utils.tuples.facade.HasTenth;
import com.mmnaseri.utils.tuples.facade.HasThird;

import java.util.function.Function;
import java.util.function.Supplier;

import static com.mmnaseri.utils.tuples.utils.TupleUtils.checkIndex;

/**
 * Class for dealing with a {@link com.mmnaseri.utils.tuples.FixedTuple} with ten elements.
 *
 * @author Milad Naseri ([email protected])
 */
public class TenTuple<
        Z,
        A extends Z,
        B extends Z,
        C extends Z,
        D extends Z,
        E extends Z,
        F extends Z,
        G extends Z,
        H extends Z,
        I extends Z,
        J extends Z>
    extends AbstractFixedTuple>
    implements HasFirst>,
        HasSecond>,
        HasThird>,
        HasFourth>,
        HasFifth>,
        HasSixth>,
        HasSeventh>,
        HasEighth>,
        HasNinth>,
        HasTenth> {

  /** Creates a new instance of this class from the provided values. */
  public TenTuple(
      A first,
      B second,
      C third,
      D fourth,
      E fifth,
      F sixth,
      G seventh,
      H eighth,
      I ninth,
      J tenth) {
    super(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth);
  }

  /**
   * Returns a new tuple by keeping all the values from this tuple and overriding the value at the
   * provided index with the value returned from the supplier.
   */
  @Override
  public TenTuple change(
      int index, Supplier supplier) {
    checkIndex(index, size());
    return new TenTuple<>(
        index == 0 ? supplier.get() : first(),
        index == 1 ? supplier.get() : second(),
        index == 2 ? supplier.get() : third(),
        index == 3 ? supplier.get() : fourth(),
        index == 4 ? supplier.get() : fifth(),
        index == 5 ? supplier.get() : sixth(),
        index == 6 ? supplier.get() : seventh(),
        index == 7 ? supplier.get() : eighth(),
        index == 8 ? supplier.get() : ninth(),
        index == 9 ? supplier.get() : tenth());
  }

  /**
   * Returns a new tuple by keeping all the values from this tuple and overriding the value at the
   * provided index with the value returned from the function.
   */
  @Override
  public TenTuple change(
      int index, Function, ? extends Z> function) {
    checkIndex(index, size());
    return new TenTuple<>(
        index == 0 ? function.apply(this) : first(),
        index == 1 ? function.apply(this) : second(),
        index == 2 ? function.apply(this) : third(),
        index == 3 ? function.apply(this) : fourth(),
        index == 4 ? function.apply(this) : fifth(),
        index == 5 ? function.apply(this) : sixth(),
        index == 6 ? function.apply(this) : seventh(),
        index == 7 ? function.apply(this) : eighth(),
        index == 8 ? function.apply(this) : ninth(),
        index == 9 ? function.apply(this) : tenth());
  }

  /**
   * Returns a new tuple of one size larger by adding the provided value to the end of this tuple.
   */
  @Override
  public  ElevenTuple extend(X value) {
    return new ElevenTuple<>(
        first(), second(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth(),
        tenth(), value);
  }

  /**
   * Returns a new tuple of one size larger by adding the value returned from the supplier to the
   * end of this tuple.
   */
  @Override
  public  ElevenTuple extend(
      Supplier supplier) {
    return new ElevenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        tenth(),
        supplier.get());
  }

  /**
   * Returns a new tuple of one size larger by adding the value returned from the function to the
   * end of this tuple.
   */
  @Override
  public  ElevenTuple extend(
      Function, X> function) {
    return new ElevenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        tenth(),
        function.apply(this));
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the first element with the provided value.
   */
  @Override
  public  TenTuple first(X value) {
    return new TenTuple<>(
        value, second(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the first element with the value returned from the given supplier.
   */
  @Override
  public  TenTuple first(Supplier supplier) {
    return new TenTuple<>(
        supplier.get(),
        second(),
        third(),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the first element with the value returned by applying the given function to this tuple's first
   * element.
   */
  @Override
  public  TenTuple first(Function function) {
    return new TenTuple<>(
        function.apply(first()),
        second(),
        third(),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of one size smaller by keeping all the values from this tuple except the
   * first element.
   */
  @Override
  public NineTuple dropFirst() {
    return new NineTuple<>(
        second(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth(), tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the second element with the provided value.
   */
  @Override
  public  TenTuple second(X value) {
    return new TenTuple<>(
        first(), value, third(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth(), tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the second element with the value returned from the given supplier.
   */
  @Override
  public  TenTuple second(Supplier supplier) {
    return new TenTuple<>(
        first(),
        supplier.get(),
        third(),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the second element with the value returned by applying the given function to this tuple's
   * second element.
   */
  @Override
  public  TenTuple second(Function function) {
    return new TenTuple<>(
        first(),
        function.apply(second()),
        third(),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of one size smaller by keeping all the values from this tuple except the
   * second element.
   */
  @Override
  public NineTuple dropSecond() {
    return new NineTuple<>(
        first(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth(), tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the third element with the provided value.
   */
  @Override
  public  TenTuple third(X value) {
    return new TenTuple<>(
        first(), second(), value, fourth(), fifth(), sixth(), seventh(), eighth(), ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the third element with the value returned from the given supplier.
   */
  @Override
  public  TenTuple third(Supplier supplier) {
    return new TenTuple<>(
        first(),
        second(),
        supplier.get(),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the third element with the value returned by applying the given function to this tuple's third
   * element.
   */
  @Override
  public  TenTuple third(Function function) {
    return new TenTuple<>(
        first(),
        second(),
        function.apply(third()),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of one size smaller by keeping all the values from this tuple except the
   * third element.
   */
  @Override
  public NineTuple dropThird() {
    return new NineTuple<>(
        first(), second(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth(), tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the fourth element with the provided value.
   */
  @Override
  public  TenTuple fourth(X value) {
    return new TenTuple<>(
        first(), second(), third(), value, fifth(), sixth(), seventh(), eighth(), ninth(), tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the fourth element with the value returned from the given supplier.
   */
  @Override
  public  TenTuple fourth(Supplier supplier) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        supplier.get(),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the fourth element with the value returned by applying the given function to this tuple's
   * fourth element.
   */
  @Override
  public  TenTuple fourth(Function function) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        function.apply(fourth()),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of one size smaller by keeping all the values from this tuple except the
   * fourth element.
   */
  @Override
  public NineTuple dropFourth() {
    return new NineTuple<>(
        first(), second(), third(), fifth(), sixth(), seventh(), eighth(), ninth(), tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the fifth element with the provided value.
   */
  @Override
  public  TenTuple fifth(X value) {
    return new TenTuple<>(
        first(), second(), third(), fourth(), value, sixth(), seventh(), eighth(), ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the fifth element with the value returned from the given supplier.
   */
  @Override
  public  TenTuple fifth(Supplier supplier) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        supplier.get(),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the fifth element with the value returned by applying the given function to this tuple's fifth
   * element.
   */
  @Override
  public  TenTuple fifth(Function function) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        function.apply(fifth()),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of one size smaller by keeping all the values from this tuple except the
   * fifth element.
   */
  @Override
  public NineTuple dropFifth() {
    return new NineTuple<>(
        first(), second(), third(), fourth(), sixth(), seventh(), eighth(), ninth(), tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the sixth element with the provided value.
   */
  @Override
  public  TenTuple sixth(X value) {
    return new TenTuple<>(
        first(), second(), third(), fourth(), fifth(), value, seventh(), eighth(), ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the sixth element with the value returned from the given supplier.
   */
  @Override
  public  TenTuple sixth(Supplier supplier) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        fifth(),
        supplier.get(),
        seventh(),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the sixth element with the value returned by applying the given function to this tuple's sixth
   * element.
   */
  @Override
  public  TenTuple sixth(Function function) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        fifth(),
        function.apply(sixth()),
        seventh(),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of one size smaller by keeping all the values from this tuple except the
   * sixth element.
   */
  @Override
  public NineTuple dropSixth() {
    return new NineTuple<>(
        first(), second(), third(), fourth(), fifth(), seventh(), eighth(), ninth(), tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the seventh element with the provided value.
   */
  @Override
  public  TenTuple seventh(X value) {
    return new TenTuple<>(
        first(), second(), third(), fourth(), fifth(), sixth(), value, eighth(), ninth(), tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the seventh element with the value returned from the given supplier.
   */
  @Override
  public  TenTuple seventh(Supplier supplier) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        fifth(),
        sixth(),
        supplier.get(),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the seventh element with the value returned by applying the given function to this tuple's
   * seventh element.
   */
  @Override
  public  TenTuple seventh(Function function) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        fifth(),
        sixth(),
        function.apply(seventh()),
        eighth(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of one size smaller by keeping all the values from this tuple except the
   * seventh element.
   */
  @Override
  public NineTuple dropSeventh() {
    return new NineTuple<>(
        first(), second(), third(), fourth(), fifth(), sixth(), eighth(), ninth(), tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the eighth element with the provided value.
   */
  @Override
  public  TenTuple eighth(X value) {
    return new TenTuple<>(
        first(), second(), third(), fourth(), fifth(), sixth(), seventh(), value, ninth(), tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the eighth element with the value returned from the given supplier.
   */
  @Override
  public  TenTuple eighth(Supplier supplier) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        supplier.get(),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the eighth element with the value returned by applying the given function to this tuple's
   * eighth element.
   */
  @Override
  public  TenTuple eighth(Function function) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        function.apply(eighth()),
        ninth(),
        tenth());
  }

  /**
   * Returns a new tuple of one size smaller by keeping all the values from this tuple except the
   * eighth element.
   */
  @Override
  public NineTuple dropEighth() {
    return new NineTuple<>(
        first(), second(), third(), fourth(), fifth(), sixth(), seventh(), ninth(), tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the ninth element with the provided value.
   */
  @Override
  public  TenTuple ninth(X value) {
    return new TenTuple<>(
        first(), second(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), value,
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the ninth element with the value returned from the given supplier.
   */
  @Override
  public  TenTuple ninth(Supplier supplier) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        supplier.get(),
        tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the ninth element with the value returned by applying the given function to this tuple's ninth
   * element.
   */
  @Override
  public  TenTuple ninth(Function function) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        function.apply(ninth()),
        tenth());
  }

  /**
   * Returns a new tuple of one size smaller by keeping all the values from this tuple except the
   * ninth element.
   */
  @Override
  public NineTuple dropNinth() {
    return new NineTuple<>(
        first(), second(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), tenth());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the tenth element with the provided value.
   */
  @Override
  public  TenTuple tenth(X value) {
    return new TenTuple<>(
        first(), second(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth(),
        value);
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the tenth element with the value returned from the given supplier.
   */
  @Override
  public  TenTuple tenth(Supplier supplier) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        supplier.get());
  }

  /**
   * Returns a new tuple of the same size by keeping all the values from this tuple and overriding
   * the tenth element with the value returned by applying the given function to this tuple's tenth
   * element.
   */
  @Override
  public  TenTuple tenth(Function function) {
    return new TenTuple<>(
        first(),
        second(),
        third(),
        fourth(),
        fifth(),
        sixth(),
        seventh(),
        eighth(),
        ninth(),
        function.apply(tenth()));
  }

  /**
   * Returns a new tuple of one size smaller by keeping all the values from this tuple except the
   * tenth element.
   */
  @Override
  public NineTuple dropTenth() {
    return new NineTuple<>(
        first(), second(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth());
  }

  /**
   * Extends the tuple to which this is applied by adding the provided value to the end.
   *
   * 

This is especially useful in functional contexts. For instance: * *

   * elevenTupleStream = tenTupleStream.map(TenTuple.extendWith(value));
   * 
* * @see #extend(Object) */ public static < Z, A extends Z, B extends Z, C extends Z, D extends Z, E extends Z, F extends Z, G extends Z, H extends Z, I extends Z, J extends Z, X extends Z> Function< TenTuple, ElevenTuple> extendWith(X value) { return tuple -> tuple.extend(value); } /** * Extends the tuple to which this is applied by adding the value from the supplier to the end. * *

This is especially useful in functional contexts. For instance: * *

   * elevenTupleStream = tenTupleStream.map(TenTuple.extendWith(supplier));
   * 
* * @see #extend(Object) */ public static < Z, A extends Z, B extends Z, C extends Z, D extends Z, E extends Z, F extends Z, G extends Z, H extends Z, I extends Z, J extends Z, X extends Z> Function< TenTuple, ElevenTuple> extendWith(Supplier supplier) { return tuple -> tuple.extend(supplier); } /** * Extends the tuple to which this is applied by adding the value from the function to the end. * *

This is especially useful in functional contexts. For instance: * *

   * elevenTupleStream = tenTupleStream.map(TenTuple.extendWith(function));
   * 
* * @see #extend(Object) */ public static < Z, A extends Z, B extends Z, C extends Z, D extends Z, E extends Z, F extends Z, G extends Z, H extends Z, I extends Z, J extends Z, X extends Z> Function< TenTuple, ElevenTuple> extendWith(Function, X> function) { return tuple -> tuple.extend(function); } /** Creates a new instance of this class. */ public static < Z, A extends Z, B extends Z, C extends Z, D extends Z, E extends Z, F extends Z, G extends Z, H extends Z, I extends Z, J extends Z> TenTuple of( A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eighth, I ninth, J tenth) { return new TenTuple<>( first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy