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

ch.openchvote.utilities.tuples.decuple.Decuple Maven / Gradle / Ivy

Go to download

This module provides a collection of utility classes, especially for various mathematical concepts.

The newest version!
/*
 * Copyright (C) 2024 Berner Fachhochschule https://e-voting.bfh.ch
 *
 *  - This program is free software: you can redistribute it and/or modify                           -
 *  - it under the terms of the GNU Affero General Public License as published by                    -
 *  - the Free Software Foundation, either version 3 of the License, or                              -
 *  - (at your option) any later version.                                                            -
 *  -                                                                                                -
 *  - This program is distributed in the hope that it will be useful,                                -
 *  - but WITHOUT ANY WARRANTY; without even the implied warranty of                                 -
 *  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                                   -
 *  - GNU General Public License for more details.                                                   -
 *  -                                                                                                -
 *  - You should have received a copy of the GNU Affero General Public License                       -
 *  - along with this program. If not, see .                           -
 */
package ch.openchvote.utilities.tuples.decuple;

import ch.openchvote.utilities.UtilityException;
import ch.openchvote.utilities.tuples.Tuple;

import java.util.stream.Stream;

import static ch.openchvote.utilities.UtilityException.Type.NULL_POINTER;

/**
 * This class implements a 10-tuple (decuple) of non-null values of different generic types.
 *
 * @param   The generic type of the first value
 * @param   The generic type of the second value
 * @param   The generic type of the third value
 * @param   The generic type of the fourth value
 * @param   The generic type of the fifth value
 * @param   The generic type of the sixth value
 * @param   The generic type of the seventh value
 * @param   The generic type of the eighth value
 * @param   The generic type of the ninth value
 * @param  The generic type of the tenth value
 */
@SuppressWarnings("unused")
public non-sealed class Decuple extends Tuple {

    private final V1 first;
    private final V2 second;
    private final V3 third;
    private final V4 fourth;
    private final V5 fifth;
    private final V6 sixth;
    private final V7 seventh;
    private final V8 eighth;
    private final V9 ninth;
    private final V10 tenth;

    /**
     * Constructs a new decuple for the given non-null values. An exception is thrown if one of the given values is
     * {@code null}.
     *
     * @param first   First value
     * @param second  Second value
     * @param third   Third value
     * @param fourth  Fourth value
     * @param fifth   Fifth value
     * @param sixth   Sixth value
     * @param seventh Seventh value
     * @param eighth  Eighth value
     * @param ninth   Ninth value
     * @param tenth   Tenth value
     */
    public Decuple(V1 first, V2 second, V3 third, V4 fourth, V5 fifth, V6 sixth, V7 seventh, V8 eighth, V9 ninth, V10 tenth) {
        if (first == null || second == null || third == null || fourth == null || fifth == null || sixth == null || seventh == null || eighth == null || ninth == null || tenth == null) {
            throw new UtilityException(NULL_POINTER, Decuple.class, "Null value not allowed for tuples");
        }
        this.first = first;
        this.second = second;
        this.third = third;
        this.fourth = fourth;
        this.fifth = fifth;
        this.sixth = sixth;
        this.seventh = seventh;
        this.eighth = eighth;
        this.ninth = ninth;
        this.tenth = tenth;
    }

    /**
     * Returns the first element of the decuple.
     *
     * @return The first element
     */
    public final V1 getFirst() {
        return this.first;
    }

    /**
     * Returns the second element of the decuple.
     *
     * @return The second element
     */
    public final V2 getSecond() {
        return this.second;
    }

    /**
     * Returns the third element of the decuple.
     *
     * @return The third element
     */
    public final V3 getThird() {
        return this.third;
    }

    /**
     * Returns the fourth element of the decuple.
     *
     * @return The fourth element
     */
    public final V4 getFourth() {
        return this.fourth;
    }

    /**
     * Returns the fifth element of the decuple.
     *
     * @return The fifth element
     */
    public final V5 getFifth() {
        return this.fifth;
    }

    /**
     * Returns the sixth element of the decuple.
     *
     * @return The sixth element
     */
    public final V6 getSixth() {
        return this.sixth;
    }

    /**
     * Returns the seventh element of the decuple.
     *
     * @return The seventh element
     */
    public final V7 getSeventh() {
        return this.seventh;
    }

    /**
     * Returns the eighth element of the decuple.
     *
     * @return The eighth element
     */
    public final V8 getEighth() {
        return this.eighth;
    }

    /**
     * Returns the ninth element of the decuple.
     *
     * @return The ninth element
     */
    public final V9 getNinth() {
        return this.ninth;
    }

    /**
     * Returns the tenth element of the decuple.
     *
     * @return The tenth element
     */
    public final V10 getTenth() {
        return this.tenth;
    }

    @Override
    public final Stream toStream() {
        return Stream.builder()
                .add(this.first)
                .add(this.second)
                .add(this.third)
                .add(this.fourth)
                .add(this.fifth)
                .add(this.sixth)
                .add(this.seventh)
                .add(this.eighth)
                .add(this.ninth)
                .add(this.tenth)
                .build();
    }

}