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

net.calledtoconstruct.Tuple8 Maven / Gradle / Ivy

Go to download

A small collection of potentially useful classes for streamlining process flow.

The newest version!
package net.calledtoconstruct;

import java.util.Optional;

public class Tuple8 implements Tuple {

    private final T1 firstValue;
    private final T2 secondValue;
    private final T3 thirdValue;
    private final T4 fourthValue;
    private final T5 fifthValue;
    private final T6 sixthValue;
    private final T7 seventhValue;
    private final T8 eighthValue;

    public Tuple8(T1 firstValue, T2 secondValue, T3 thirdValue, T4 fourthValue, T5 fifthValue, T6 sixthValue, T7 seventhValue, T8 eighthValue) {
        this.firstValue = firstValue;
        this.secondValue = secondValue;
        this.thirdValue = thirdValue;
        this.fourthValue = fourthValue;
        this.fifthValue = fifthValue;
        this.sixthValue = sixthValue;
        this.seventhValue = seventhValue;
        this.eighthValue = eighthValue;
    }

    /**
     * A function that returns a new instance of {@link Tuple7} containing the
     * first seven values from this instance.
     * 
     * @return A {@link Tuple7} containing the first seven values from this instance.
     */
    public Tuple7 pop() {
        return new Tuple7<>(firstValue, secondValue, thirdValue, fourthValue, fifthValue, sixthValue, seventhValue);
    }

    /**
     * A function that returns a new instance of {@link Tuple7} containing the
     * last seven values from this instance.
     * 
     * @return A {@link Tuple7} containing the last seven values from this instance.
     */
    public Tuple7 shift() {
        return new Tuple7<>(secondValue, thirdValue, fourthValue, fifthValue, sixthValue, seventhValue, eighthValue);
    }

    @Override
    public Optional tryPop() {
        return Optional.of(pop());
    }

    @Override
    public  Optional tryPush(T value) {
        return Optional.empty();
    }

    @Override
    public Optional tryShift() {
        return Optional.of(shift());
    }

    @Override
    public  Optional tryUnshift(T value) {
        return Optional.empty();
    }

    /**
     * A function that returns the first value from this instance.
     * 
     * @return A value of type {@code T1}
     */
    public T1 getFirst() {
        return firstValue;
    }

    /**
     * A function that returns the second value from this instance.
     * 
     * @return A value of type {@code T2}
     */
    public T2 getSecond() {
        return secondValue;
    }

    /**
     * A function that returns the third value from this instance.
     * 
     * @return A value of type {@code T3}
     */
    public T3 getThird() {
        return thirdValue;
    }

    /**
     * A function that returns the fourth value from this instance.
     * 
     * @return A value of type {@code T4}
     */
    public T4 getFourth() {
        return fourthValue;
    }

    /**
     * A function that returns the fifth value from this instance.
     * 
     * @return A value of type {@code T5}
     */
    public T5 getFifth() {
        return fifthValue;
    }

    /**
     * A function that returns the sixth value from this instance.
     * 
     * @return A value of type {@code T6}
     */
    public T6 getSixth() {
        return sixthValue;
    }

    /**
     * A function that returns the seventh value from this instance.
     * 
     * @return A value of type {@code T7}
     */
    public T7 getSeventh() {
        return seventhValue;
    }

    /**
     * A function that returns the eighth value from this instance.
     * 
     * @return A value of type {@code T8}
     */
    public T8 getEighth() {
        return eighthValue;
    }

    @Override
    public  Optional tryGetFirst(Class clazz) {
        if (clazz.isAssignableFrom(firstValue.getClass())) {
            final var cast = clazz.cast(firstValue);
            return Optional.of(cast);
        }
        return Optional.empty();
    }

    @Override
    public  Optional tryGetLast(Class clazz) {
        if (clazz.isAssignableFrom(eighthValue.getClass())) {
            final var cast = clazz.cast(eighthValue);
            return Optional.of(cast);
        }
        return Optional.empty();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy