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

org.jmmo.tuple.Tuple9 Maven / Gradle / Ivy

package org.jmmo.tuple;

import org.jmmo.function.Consumer9;
import org.jmmo.function.Function9;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Objects;

public class Tuple9 implements Tuple, Comparable> {
    private static final long serialVersionUID = 2941741413856270109L;

    private final T0 value0;
    private final T1 value1;
    private final T2 value2;
    private final T3 value3;
    private final T4 value4;
    private final T5 value5;
    private final T6 value6;
    private final T7 value7;
    private final T8 value8;

    protected Tuple9(T0 value0, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8) {
        this.value0 = value0;
        this.value1 = value1;
        this.value2 = value2;
        this.value3 = value3;
        this.value4 = value4;
        this.value5 = value5;
        this.value6 = value6;
        this.value7 = value7;
        this.value8 = value8;
    }

    public static  Tuple9 of(
            V0 v0, V1 v1, V2 v2, V3 v3, V4 v4, V5 v5, V6 v6, V7 v7, V8 v8) {
        return new Tuple9<>(v0, v1, v2, v3, v4, v5, v6, v7, v8);
    }

    @SuppressWarnings("unchecked")
    public static 
    Tuple9 fromArray(A[] values) {
        return new Tuple9<>((V0) values[0], (V1) values[1], (V2) values[2], (V3) values[3], (V4) values[4],
                (V5) values[5], (V6) values[6], (V7) values[7], (V8) values[8]);
    }

    @SuppressWarnings("unchecked")
    public static 
    Tuple9 fromIterator(Iterator iterator) {
        return new Tuple9<>((V0) iterator.next(), (V1) iterator.next(), (V2) iterator.next(),
                (V3) iterator.next(), (V4) iterator.next(), (V5) iterator.next(),
                (V6) iterator.next(), (V7) iterator.next(), (V8) iterator.next());
    }

    public void unfold(Consumer9 valueConsumer) {
        valueConsumer.accept(getValue0(), getValue1(), getValue2(), getValue3(), getValue4(), getValue5(),
                getValue6(), getValue7(), getValue8());
    }

    public  R unfoldResult(Function9 valueFunction) {
        return valueFunction.apply(getValue0(), getValue1(), getValue2(), getValue3(), getValue4(), getValue5(),
                getValue6(), getValue7(), getValue8());
    }

    public T0 getValue0() {
        return value0;
    }

    public T1 getValue1() {
        return value1;
    }

    public T2 getValue2() {
        return value2;
    }

    public T3 getValue3() {
        return value3;
    }

    public T4 getValue4() {
        return value4;
    }

    public T5 getValue5() {
        return value5;
    }

    public T6 getValue6() {
        return value6;
    }

    public T7 getValue7() {
        return value7;
    }

    public T8 getValue8() {
        return value8;
    }

    @Override public int getSize() {
        return 9;
    }

    @SuppressWarnings("unchecked")
    @Override public  E get(int i) {
        switch (i) {
            case 0: return (E) getValue0();
            case 1: return (E) getValue1();
            case 2: return (E) getValue2();
            case 3: return (E) getValue3();
            case 4: return (E) getValue4();
            case 5: return (E) getValue5();
            case 6: return (E) getValue6();
            case 7: return (E) getValue7();
            case 8: return (E) getValue8();
        }

        throw new IndexOutOfBoundsException("Tuple9 contains nine elements but " + i + " element requested");
    }

    @Override public Object[] toArray() {
        return new Object[] { getValue0(), getValue1(), getValue2(), getValue3(), getValue4(), getValue5(),
                getValue6(), getValue7(), getValue8() };
    }

    @SuppressWarnings("unchecked")
    private static final Comparator comparator =
            Comparator.>comparing(tuple -> (Comparable) tuple.getValue0(), Tuple1.nullComparator)
            .thenComparing(
            Comparator.>comparing(tuple -> (Comparable) tuple.getValue1(), Tuple1.nullComparator))
            .thenComparing(
            Comparator.>comparing(tuple -> (Comparable) tuple.getValue2(), Tuple1.nullComparator))
            .thenComparing(
            Comparator.>comparing(tuple -> (Comparable) tuple.getValue3(), Tuple1.nullComparator))
            .thenComparing(
            Comparator.>comparing(tuple -> (Comparable) tuple.getValue4(), Tuple1.nullComparator))
            .thenComparing(
            Comparator.>comparing(tuple -> (Comparable) tuple.getValue5(), Tuple1.nullComparator))
            .thenComparing(
            Comparator.>comparing(tuple -> (Comparable) tuple.getValue6(), Tuple1.nullComparator)
            .thenComparing(
            Comparator.>comparing(tuple -> (Comparable) tuple.getValue7(), Tuple1.nullComparator))
            .thenComparing(
            Comparator.>comparing(tuple -> (Comparable) tuple.getValue8(), Tuple1.nullComparator)));

    @SuppressWarnings("unchecked")
    @Override public int compareTo(Tuple9 o) {
        return comparator.compare(this, o);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Tuple9)) return false;
        Tuple9 tuple9 = (Tuple9) o;
        return Objects.deepEquals(getValue0(), tuple9.getValue0()) &&
                Objects.deepEquals(getValue1(), tuple9.getValue1()) &&
                Objects.deepEquals(getValue2(), tuple9.getValue2()) &&
                Objects.deepEquals(getValue3(), tuple9.getValue3()) &&
                Objects.deepEquals(getValue4(), tuple9.getValue4()) &&
                Objects.deepEquals(getValue5(), tuple9.getValue5()) &&
                Objects.deepEquals(getValue6(), tuple9.getValue6()) &&
                Objects.deepEquals(getValue7(), tuple9.getValue7()) &&
                Objects.deepEquals(getValue8(), tuple9.getValue8());
    }

    @Override public int hashCode() {
        return Tuple.hashCode(this);
    }

    @Override public String toString() {
        return Tuple.toString(this);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy