kodkod.instance
Class Tuple

java.lang.Object
  extended by kodkod.instance.Tuple

public abstract class Tuple
extends java.lang.Object

Represents a sequence of atoms drawn from a given universe. Note that a Tuple of arity n whose atoms belong to a Universe u encodes an n-digit number in base u.size. The decimal representation of this number is taken to be the index of the tuple in an n-dimensional space over the Universe u.

Author:
Emina Torlak
invariant:
atoms[int] in universe.atoms[int]
specfield:
arity: int
universe: Universe
atoms: [0..arity)->one Object

Constructor Summary
Tuple()
           
 
Method Summary
abstract  int arity()
          Returns the arity of this tuple.
abstract  java.lang.Object atom(int i)
          Returns the atom at the specified index
abstract  int atomIndex(int i)
          Returns the index of the ith atom as given by this.universe.
abstract  boolean contains(java.lang.Object atom)
          Returns true if atom is in this tuple, otherwise returns false.
 boolean equals(java.lang.Object o)
          Returns true if o is a tuple with the same sequence of atoms as this, drawn from the same universe as this.
 int hashCode()
          Returns a hash code based on the tuple's arity, index, and the hash code of its universe, so that the general contract of Object.hashCode is obeyed.
abstract  int index()
          A Tuple encodes a number with this.arity digits in radix this.universe.size; a Tuple's index is the decimal representation of this number.
abstract  Tuple product(Tuple tuple)
          Returns the cross product of this and the specified tuple.
 java.lang.String toString()
           
abstract  Universe universe()
          Returns the universe from which the atoms in this tuple are drawn.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Tuple

public Tuple()
Method Detail

universe

public abstract Universe universe()
Returns the universe from which the atoms in this tuple are drawn.

Returns:
this.universe

arity

public abstract int arity()
Returns the arity of this tuple.

Returns:
this.arity

index

public abstract int index()
A Tuple encodes a number with this.arity digits in radix this.universe.size; a Tuple's index is the decimal representation of this number.

Returns:
sum({i: [0..arity) | universe.index(atoms[i]) * universe.size^(arity - 1 - i)})

atom

public abstract java.lang.Object atom(int i)
Returns the atom at the specified index

Returns:
this.atoms[i]
Throws:
java.lang.IndexOutOfBoundsException - - i < 0 || i >= this.arity

atomIndex

public abstract int atomIndex(int i)
Returns the index of the ith atom as given by this.universe. The effect of this method is the same as calling this.universe.index(this.atom(i)).

Returns:
this.universe.index(this.atoms[i])
Throws:
java.lang.IndexOutOfBoundsException - - i < 0 || i >= this.arity

contains

public abstract boolean contains(java.lang.Object atom)
Returns true if atom is in this tuple, otherwise returns false.

Returns:
atom in this.atoms[int]
Throws:
java.lang.IllegalArgumentException - - atom !in this.universe.atoms[int]

product

public abstract Tuple product(Tuple tuple)
Returns the cross product of this and the specified tuple.

Returns:
{t : Tuple | t.atoms = this.atoms->tuple.atoms}
Throws:
java.lang.NullPointerException - - tuple = null
java.lang.IllegalArgumentException - - tuple.universe != this.universe

equals

public boolean equals(java.lang.Object o)
Returns true if o is a tuple with the same sequence of atoms as this, drawn from the same universe as this. Otherwise returns false.

Overrides:
equals in class java.lang.Object
Returns:
o in Tuple && o.universe = this.universe && o.atoms = this.atoms

hashCode

public int hashCode()
Returns a hash code based on the tuple's arity, index, and the hash code of its universe, so that the general contract of Object.hashCode is obeyed.

Overrides:
hashCode in class java.lang.Object
Returns:
the hashcode for this tuple

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()