Tuple#

public final class Tuple#

An immutable tuple. All methods of this class throw a NullPointerException if a null object reference is passed in any parameter.

Fields#

_impl#

TupleBase _impl#

Constructors#

Tuple#

public Tuple(Object... elements)#

Constructs a new Tuple from the specified elements.

The elements in a Tuple can be numbers or strings.

All basic Java numeric types are converted to double, as AMPL supports only one numeric type.

Tuple#

public Tuple(int[] elements)#

Tuple#

public Tuple(double[] elements)#

Tuple#

public Tuple(String[] elements)#

Methods#

elements#

public Object[] elements()#

Returns a new array containing the tuple elements.

equals#

public boolean equals(Object other)#

Checks for deep equality

factory#

static Tuple factory(TupleRefBase tr)#

get#

public Object get(int index)#

Returns the element at the specified position in this tuple.

hashCode#

public int hashCode()#

Hash code of all elements

join#

public static Tuple join(Object... elements)#

Constructs a new Tuple joining the specified elements.

The elements in a Tuple can be numbers, strings, tuples or arrays.

Use this function to construct a tuple for accessing instances of AMPL entities indexed over 2 or more index sets at least one of which is two-dimensional.

For example, accessing the AMPL entity:

var x{{(1,2)}, {'a'}};

can be achieved either via:

Variable x = ampl.getVariable("x");
x.get(1, 2, "a");

or, using this function, as:

Variable x = ampl.getVariable("x");
Tuple t = new Tuple(1, 2);
x.get(Tuple.join(t, "a"));

The very same way, the elements of the tuple created by:

t = Tuple.join(new Object[] { 2, 3 }, 4, "b";);

will be equivalent to

t = new Tuple(2, 3, 4, "b").

or, by joining tuples:

Tuple A = new Tuple(2, 3);
Tuple B = Tuple.join(A, A);

is equivalent to:

Tuple B = new Tuple(2, 3, 2, 3);

Note that to conform with the AMPL type system all basic Java numeric types are converted to double, as AMPL supports only one numeric type (see Tuple.Tuple for more information).

size#

public int size()#

Returns the number of elements in this tuple.

toString#

public String toString()#

Returns a string of the form (t1,t2,t3) where t1, t2, t3 are the elements of the tuple