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

org.javatuples.Unit Maven / Gradle / Ivy

There is a newer version: 4.15.102
Show newest version
/*
 * =============================================================================
 * 
 *   Copyright (c) 2010, The JAVATUPLES team (http://www.javatuples.org)
 * 
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * 
 * =============================================================================
 */
package org.javatuples;

import java.util.Collection;
import java.util.Iterator;

import org.javatuples.valueintf.IValue0;

/**
 * 

* A tuple of one element. *

* * @since 1.0 * * @author Daniel Fernández * */ public final class Unit extends Tuple implements IValue0 { private static final long serialVersionUID = -9113114724069537096L; private static final int SIZE = 1; private final A val0; public static Unit with(final A value0) { return new Unit(value0); } /** *

* Create tuple from array. Array has to have exactly one element. *

* * @param the array component type * @param array the array to be converted to a tuple * @return the tuple */ public static Unit fromArray(final X[] array) { if (array == null) { throw new IllegalArgumentException("Array cannot be null"); } if (array.length != 1) { throw new IllegalArgumentException("Array must have exactly 1 element in order to create a Unit. Size is " + array.length); } return new Unit(array[0]); } /** *

* Create tuple from collection. Collection has to have exactly one element. *

* * @param the collection component type * @param collection the collection to be converted to a tuple * @return the tuple */ public static Unit fromCollection(final Collection collection) { if (collection == null) { throw new IllegalArgumentException("Collection cannot be null"); } if (collection.size() != 1) { throw new IllegalArgumentException("Collection must have exactly 1 element in order to create a Unit. Size is " + collection.size()); } final Iterator iter = collection.iterator(); return new Unit(iter.next()); } /** *

* Create tuple from iterable. Iterable has to have exactly one element. *

* * @param the iterable component type * @param iterable the iterable to be converted to a tuple * @return the tuple */ public static Unit fromIterable(final Iterable iterable) { return fromIterable(iterable, 0, true); } /** *

* Create tuple from iterable, starting from the specified index. Iterable * can have more (or less) elements than the tuple to be created. *

* * @param the iterable component type * @param iterable the iterable to be converted to a tuple * @return the tuple */ public static Unit fromIterable(final Iterable iterable, int index) { return fromIterable(iterable, index, false); } private static Unit fromIterable(final Iterable iterable, int index, final boolean exactSize) { if (iterable == null) { throw new IllegalArgumentException("Iterable cannot be null"); } boolean tooFewElements = false; X element0 = null; final Iterator iter = iterable.iterator(); int i = 0; while (i < index) { if (iter.hasNext()) { iter.next(); } else { tooFewElements = true; } i++; } if (iter.hasNext()) { element0 = iter.next(); } else { tooFewElements = true; } if (tooFewElements && exactSize) { throw new IllegalArgumentException("Not enough elements for creating a Unit (1 needed)"); } if (iter.hasNext() && exactSize) { throw new IllegalArgumentException("Iterable must have exactly 1 available element in order to create a Unit."); } return new Unit(element0); } public Unit(final A value0) { super(value0); this.val0 = value0; } public A getValue0() { return this.val0; } @Override public int getSize() { return SIZE; } public Pair addAt0(final X0 value0) { return new Pair( value0, this.val0); } public Pair addAt1(final X0 value0) { return new Pair( this.val0, value0); } public Triplet addAt0(final X0 value0, final X1 value1) { return new Triplet( value0, value1, this.val0); } public Triplet addAt1(final X0 value0, final X1 value1) { return new Triplet( this.val0, value0, value1); } public Quartet addAt0(final X0 value0, final X1 value1, final X2 value2) { return new Quartet( value0, value1, value2, this.val0); } public Quartet addAt1(final X0 value0, final X1 value1, final X2 value2) { return new Quartet( this.val0, value0, value1, value2); } public Quintet addAt0(final X0 value0, final X1 value1, final X2 value2, final X3 value3) { return new Quintet( value0, value1, value2, value3, this.val0); } public Quintet addAt1(final X0 value0, final X1 value1, final X2 value2, final X3 value3) { return new Quintet( this.val0, value0, value1, value2, value3); } public Sextet addAt0(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4) { return new Sextet( value0, value1, value2, value3, value4, this.val0); } public Sextet addAt1(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4) { return new Sextet( this.val0, value0, value1, value2, value3, value4); } public Septet addAt0(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4, final X5 value5) { return new Septet( value0, value1, value2, value3, value4, value5, this.val0); } public Septet addAt1(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4, final X5 value5) { return new Septet( this.val0, value0, value1, value2, value3, value4, value5); } public Octet addAt0(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4, final X5 value5, final X6 value6) { return new Octet( value0, value1, value2, value3, value4, value5, value6, this.val0); } public Octet addAt1(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4, final X5 value5, final X6 value6) { return new Octet( this.val0, value0, value1, value2, value3, value4, value5, value6); } public Ennead addAt0(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4, final X5 value5, final X6 value6, final X7 value7) { return new Ennead( value0, value1, value2, value3, value4, value5, value6, value7, this.val0); } public Ennead addAt1(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4, final X5 value5, final X6 value6, final X7 value7) { return new Ennead( this.val0, value0, value1, value2, value3, value4, value5, value6, value7); } public Decade addAt0(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4, final X5 value5, final X6 value6, final X7 value7, final X8 value8) { return new Decade( value0, value1, value2, value3, value4, value5, value6, value7, value8, this.val0); } public Decade addAt1(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4, final X5 value5, final X6 value6, final X7 value7, final X8 value8) { return new Decade( this.val0, value0, value1, value2, value3, value4, value5, value6, value7, value8); } public Pair addAt0(final Unit tuple) { return addAt0(tuple.getValue0()); } public Pair addAt1(final Unit tuple) { return addAt1(tuple.getValue0()); } public Triplet addAt0(final Pair tuple) { return addAt0(tuple.getValue0(),tuple.getValue1()); } public Triplet addAt1(final Pair tuple) { return addAt1(tuple.getValue0(),tuple.getValue1()); } public Quartet addAt0(final Triplet tuple) { return addAt0(tuple.getValue0(),tuple.getValue1(),tuple.getValue2()); } public Quartet addAt1(final Triplet tuple) { return addAt1(tuple.getValue0(),tuple.getValue1(),tuple.getValue2()); } public Quintet addAt0(final Quartet tuple) { return addAt0(tuple.getValue0(),tuple.getValue1(),tuple.getValue2(),tuple.getValue3()); } public Quintet addAt1(final Quartet tuple) { return addAt1(tuple.getValue0(),tuple.getValue1(),tuple.getValue2(),tuple.getValue3()); } public Sextet addAt0(final Quintet tuple) { return addAt0(tuple.getValue0(),tuple.getValue1(),tuple.getValue2(),tuple.getValue3(),tuple.getValue4()); } public Sextet addAt1(final Quintet tuple) { return addAt1(tuple.getValue0(),tuple.getValue1(),tuple.getValue2(),tuple.getValue3(),tuple.getValue4()); } public Septet addAt0(final Sextet tuple) { return addAt0(tuple.getValue0(),tuple.getValue1(),tuple.getValue2(),tuple.getValue3(),tuple.getValue4(),tuple.getValue5()); } public Septet addAt1(final Sextet tuple) { return addAt1(tuple.getValue0(),tuple.getValue1(),tuple.getValue2(),tuple.getValue3(),tuple.getValue4(),tuple.getValue5()); } public Octet addAt0(final Septet tuple) { return addAt0(tuple.getValue0(),tuple.getValue1(),tuple.getValue2(),tuple.getValue3(),tuple.getValue4(),tuple.getValue5(),tuple.getValue6()); } public Octet addAt1(final Septet tuple) { return addAt1(tuple.getValue0(),tuple.getValue1(),tuple.getValue2(),tuple.getValue3(),tuple.getValue4(),tuple.getValue5(),tuple.getValue6()); } public Ennead addAt0(final Octet tuple) { return addAt0(tuple.getValue0(),tuple.getValue1(),tuple.getValue2(),tuple.getValue3(),tuple.getValue4(),tuple.getValue5(),tuple.getValue6(),tuple.getValue7()); } public Ennead addAt1(final Octet tuple) { return addAt1(tuple.getValue0(),tuple.getValue1(),tuple.getValue2(),tuple.getValue3(),tuple.getValue4(),tuple.getValue5(),tuple.getValue6(),tuple.getValue7()); } public Decade addAt0(final Ennead tuple) { return addAt0(tuple.getValue0(),tuple.getValue1(),tuple.getValue2(),tuple.getValue3(),tuple.getValue4(),tuple.getValue5(),tuple.getValue6(),tuple.getValue7(),tuple.getValue8()); } public Decade addAt1(final Ennead tuple) { return addAt1(tuple.getValue0(),tuple.getValue1(),tuple.getValue2(),tuple.getValue3(),tuple.getValue4(),tuple.getValue5(),tuple.getValue6(),tuple.getValue7(),tuple.getValue8()); } public Pair add(final X0 value0) { return addAt1(value0); } public Pair add(final Unit tuple) { return addAt1(tuple); } public Triplet add(final X0 value0, final X1 value1) { return addAt1(value0, value1); } public Triplet add(final Pair tuple) { return addAt1(tuple); } public Quartet add(final X0 value0, final X1 value1, final X2 value2) { return addAt1(value0, value1, value2); } public Quartet add(final Triplet tuple) { return addAt1(tuple); } public Quintet add(final X0 value0, final X1 value1, final X2 value2, final X3 value3) { return addAt1(value0, value1, value2, value3); } public Quintet add(final Quartet tuple) { return addAt1(tuple); } public Sextet add(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4) { return addAt1(value0, value1, value2, value3, value4); } public Sextet add(final Quintet tuple) { return addAt1(tuple); } public Septet add(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4, final X5 value5) { return addAt1(value0, value1, value2, value3, value4, value5); } public Septet add(final Sextet tuple) { return addAt1(tuple); } public Octet add(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4, final X5 value5, final X6 value6) { return addAt1(value0, value1, value2, value3, value4, value5, value6); } public Octet add(final Septet tuple) { return addAt1(tuple); } public Ennead add(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4, final X5 value5, final X6 value6, final X7 value7) { return addAt1(value0, value1, value2, value3, value4, value5, value6, value7); } public Ennead add(final Octet tuple) { return addAt1(tuple); } public Decade add(final X0 value0, final X1 value1, final X2 value2, final X3 value3, final X4 value4, final X5 value5, final X6 value6, final X7 value7, final X8 value8) { return addAt1(value0, value1, value2, value3, value4, value5, value6, value7, value8); } public Decade add(final Ennead tuple) { return addAt1(tuple); } public Unit setAt0(final X value) { return new Unit( value); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy