com.mmnaseri.utils.tuples.impl.NineTuple Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tuples4j Show documentation
Show all versions of tuples4j Show documentation
Tiny framework for using tuples as first-class citizens in Java.
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.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 nine elements.
*
* @author Milad Naseri ([email protected])
*/
public class NineTuple<
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>
extends AbstractFixedTuple>
implements HasFirst>,
HasSecond>,
HasThird>,
HasFourth>,
HasFifth>,
HasSixth>,
HasSeventh>,
HasEighth>,
HasNinth> {
/** Creates a new instance of this class from the provided values. */
public NineTuple(
A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eighth, I ninth) {
super(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth);
}
/**
* 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 NineTuple change(int index, Supplier extends Z> supplier) {
checkIndex(index, size());
return new NineTuple<>(
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());
}
/**
* 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 NineTuple change(
int index, Function, ? extends Z> function) {
checkIndex(index, size());
return new NineTuple<>(
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());
}
/**
* Returns a new tuple of one size larger by adding the provided value to the end of this tuple.
*/
@Override
public TenTuple extend(X value) {
return new TenTuple<>(
first(), second(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth(),
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 TenTuple extend(Supplier supplier) {
return new TenTuple<>(
first(),
second(),
third(),
fourth(),
fifth(),
sixth(),
seventh(),
eighth(),
ninth(),
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 TenTuple extend(
Function, X> function) {
return new TenTuple<>(
first(),
second(),
third(),
fourth(),
fifth(),
sixth(),
seventh(),
eighth(),
ninth(),
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 NineTuple first(X value) {
return new NineTuple<>(
value, second(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth());
}
/**
* 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 NineTuple first(Supplier supplier) {
return new NineTuple<>(
supplier.get(),
second(),
third(),
fourth(),
fifth(),
sixth(),
seventh(),
eighth(),
ninth());
}
/**
* 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 NineTuple first(Function function) {
return new NineTuple<>(
function.apply(first()),
second(),
third(),
fourth(),
fifth(),
sixth(),
seventh(),
eighth(),
ninth());
}
/**
* Returns a new tuple of one size smaller by keeping all the values from this tuple except the
* first element.
*/
@Override
public EightTuple dropFirst() {
return new EightTuple<>(
second(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth());
}
/**
* 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 NineTuple second(X value) {
return new NineTuple<>(
first(), value, third(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth());
}
/**
* 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 NineTuple second(Supplier supplier) {
return new NineTuple<>(
first(), supplier.get(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth());
}
/**
* 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 NineTuple second(Function function) {
return new NineTuple<>(
first(),
function.apply(second()),
third(),
fourth(),
fifth(),
sixth(),
seventh(),
eighth(),
ninth());
}
/**
* Returns a new tuple of one size smaller by keeping all the values from this tuple except the
* second element.
*/
@Override
public EightTuple dropSecond() {
return new EightTuple<>(
first(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth());
}
/**
* 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 NineTuple third(X value) {
return new NineTuple<>(
first(), second(), value, fourth(), fifth(), sixth(), seventh(), eighth(), ninth());
}
/**
* 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 NineTuple third(Supplier supplier) {
return new NineTuple<>(
first(),
second(),
supplier.get(),
fourth(),
fifth(),
sixth(),
seventh(),
eighth(),
ninth());
}
/**
* 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 NineTuple third(Function function) {
return new NineTuple<>(
first(),
second(),
function.apply(third()),
fourth(),
fifth(),
sixth(),
seventh(),
eighth(),
ninth());
}
/**
* Returns a new tuple of one size smaller by keeping all the values from this tuple except the
* third element.
*/
@Override
public EightTuple dropThird() {
return new EightTuple<>(
first(), second(), fourth(), fifth(), sixth(), seventh(), eighth(), ninth());
}
/**
* 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 NineTuple fourth(X value) {
return new NineTuple<>(
first(), second(), third(), value, fifth(), sixth(), seventh(), eighth(), ninth());
}
/**
* 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 NineTuple fourth(Supplier supplier) {
return new NineTuple<>(
first(), second(), third(), supplier.get(), fifth(), sixth(), seventh(), eighth(), ninth());
}
/**
* 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 NineTuple fourth(Function function) {
return new NineTuple<>(
first(),
second(),
third(),
function.apply(fourth()),
fifth(),
sixth(),
seventh(),
eighth(),
ninth());
}
/**
* Returns a new tuple of one size smaller by keeping all the values from this tuple except the
* fourth element.
*/
@Override
public EightTuple dropFourth() {
return new EightTuple<>(
first(), second(), third(), fifth(), sixth(), seventh(), eighth(), ninth());
}
/**
* 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 NineTuple fifth(X value) {
return new NineTuple<>(
first(), second(), third(), fourth(), value, sixth(), seventh(), eighth(), ninth());
}
/**
* 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 NineTuple fifth(Supplier supplier) {
return new NineTuple<>(
first(),
second(),
third(),
fourth(),
supplier.get(),
sixth(),
seventh(),
eighth(),
ninth());
}
/**
* 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 NineTuple fifth(Function function) {
return new NineTuple<>(
first(),
second(),
third(),
fourth(),
function.apply(fifth()),
sixth(),
seventh(),
eighth(),
ninth());
}
/**
* Returns a new tuple of one size smaller by keeping all the values from this tuple except the
* fifth element.
*/
@Override
public EightTuple dropFifth() {
return new EightTuple<>(
first(), second(), third(), fourth(), sixth(), seventh(), eighth(), ninth());
}
/**
* 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 NineTuple sixth(X value) {
return new NineTuple<>(
first(), second(), third(), fourth(), fifth(), value, seventh(), eighth(), ninth());
}
/**
* 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 NineTuple sixth(Supplier supplier) {
return new NineTuple<>(
first(),
second(),
third(),
fourth(),
fifth(),
supplier.get(),
seventh(),
eighth(),
ninth());
}
/**
* 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 NineTuple sixth(Function function) {
return new NineTuple<>(
first(),
second(),
third(),
fourth(),
fifth(),
function.apply(sixth()),
seventh(),
eighth(),
ninth());
}
/**
* Returns a new tuple of one size smaller by keeping all the values from this tuple except the
* sixth element.
*/
@Override
public EightTuple dropSixth() {
return new EightTuple<>(
first(), second(), third(), fourth(), fifth(), seventh(), eighth(), ninth());
}
/**
* 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 NineTuple seventh(X value) {
return new NineTuple<>(
first(), second(), third(), fourth(), fifth(), sixth(), value, eighth(), ninth());
}
/**
* 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 NineTuple seventh(Supplier supplier) {
return new NineTuple<>(
first(), second(), third(), fourth(), fifth(), sixth(), supplier.get(), eighth(), ninth());
}
/**
* 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 NineTuple seventh(Function function) {
return new NineTuple<>(
first(),
second(),
third(),
fourth(),
fifth(),
sixth(),
function.apply(seventh()),
eighth(),
ninth());
}
/**
* Returns a new tuple of one size smaller by keeping all the values from this tuple except the
* seventh element.
*/
@Override
public EightTuple dropSeventh() {
return new EightTuple<>(
first(), second(), third(), fourth(), fifth(), sixth(), eighth(), ninth());
}
/**
* 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 NineTuple eighth(X value) {
return new NineTuple<>(
first(), second(), third(), fourth(), fifth(), sixth(), seventh(), value, ninth());
}
/**
* 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 NineTuple eighth(Supplier supplier) {
return new NineTuple<>(
first(), second(), third(), fourth(), fifth(), sixth(), seventh(), supplier.get(), ninth());
}
/**
* 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 NineTuple eighth(Function function) {
return new NineTuple<>(
first(),
second(),
third(),
fourth(),
fifth(),
sixth(),
seventh(),
function.apply(eighth()),
ninth());
}
/**
* Returns a new tuple of one size smaller by keeping all the values from this tuple except the
* eighth element.
*/
@Override
public EightTuple dropEighth() {
return new EightTuple<>(
first(), second(), third(), fourth(), fifth(), sixth(), seventh(), ninth());
}
/**
* 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 NineTuple ninth(X value) {
return new NineTuple<>(
first(), second(), third(), fourth(), fifth(), sixth(), seventh(), eighth(), value);
}
/**
* 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 NineTuple ninth(Supplier supplier) {
return new NineTuple<>(
first(),
second(),
third(),
fourth(),
fifth(),
sixth(),
seventh(),
eighth(),
supplier.get());
}
/**
* 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 NineTuple ninth(Function function) {
return new NineTuple<>(
first(),
second(),
third(),
fourth(),
fifth(),
sixth(),
seventh(),
eighth(),
function.apply(ninth()));
}
/**
* Returns a new tuple of one size smaller by keeping all the values from this tuple except the
* ninth element.
*/
@Override
public EightTuple dropNinth() {
return new EightTuple<>(
first(), second(), third(), fourth(), fifth(), sixth(), seventh(), eighth());
}
/**
* 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:
*
*
* tenTupleStream = nineTupleStream.map(NineTuple.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,
X extends Z>
Function, TenTuple>
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:
*
*
* tenTupleStream = nineTupleStream.map(NineTuple.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,
X extends Z>
Function, TenTuple>
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:
*
*
* tenTupleStream = nineTupleStream.map(NineTuple.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,
X extends Z>
Function, TenTuple>
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>
NineTuple of(
A first, B second, C third, D fourth, E fifth, F sixth, G seventh, H eighth, I ninth) {
return new NineTuple<>(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy