kodkod.instance
Class Universe

java.lang.Object
  extended by kodkod.instance.Universe
All Implemented Interfaces:
java.lang.Iterable<java.lang.Object>

public final class Universe
extends java.lang.Object
implements java.lang.Iterable<java.lang.Object>

Represents an ordered set of unique atoms. Objects used as atoms must properly implement equals and hashCode methods. The behavior of a universe is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is an atom in the universe.

Each universe provides a tuple factory to facilitate creation of tuples and sets of tuples based on the atoms in the universe.

Implementation Note: although the atoms in a universe are not interpreted in any way by the Kodkod engine, it is strongly recommended that the atoms of the same 'type' be grouped together. For instance, suppose that a client model is specified in terms of disjoint types Person = {Person0, Person1, Person2} and Dog = {Dog0, Dog1}. Then, the client may observe an improvement in performance if he constructs the universe over the sequences {Person0, Person1, Person2, Dog0, Dog1} or {Dog0, Dog1, Person0, Person1, Person2} rather than any other permutation of these five atoms.

Author:
Emina Torlak
invariant:
factory = (TupleFactory<:universe).this
size > 0
specfield:
size: int
atoms: [0..size)->one Object
factory: TupleFactory

Constructor Summary
Universe(java.util.Collection<?> atoms)
          Constructs a new Universe consisting of the given atoms, in the order that they are returned by the specified Collection's Iterator.
 
Method Summary
 java.lang.Object atom(int i)
          Returns the i_th atom in this universe
 boolean contains(java.lang.Object atom)
          Returns true if atom is in this universe, otherwise returns false.
 TupleFactory factory()
          Returns a TupleFactory that can be used to construct tuples and sets of tuples based on this universe.
 int index(java.lang.Object atom)
          Returns the index of the specified atom in this universe; if the atom is not in this universe, an IllegalArgumentException is thrown.
 java.util.Iterator<java.lang.Object> iterator()
          Returns an iterator over atoms in this universe, according to their order in the universe.
 int size()
          Returns the size of this universe
 java.lang.String toString()
          Returns a string representation of this universe.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Universe

public Universe(java.util.Collection<?> atoms)
Constructs a new Universe consisting of the given atoms, in the order that they are returned by the specified Collection's Iterator.

Throws:
java.lang.NullPointerException - - atoms = null
java.lang.IllegalArgumentException - - atoms contains duplicates
java.lang.IllegalArgumentException - - atoms is empty
effects:
this.size' = atoms.size && this.atoms' = atoms.iterator
Method Detail

factory

public TupleFactory factory()
Returns a TupleFactory that can be used to construct tuples and sets of tuples based on this universe.

Returns:
this.factory

size

public int size()
Returns the size of this universe

Returns:
#this.atoms

contains

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

Returns:
atom in this.atoms[int]

atom

public java.lang.Object atom(int i)
Returns the i_th atom in this universe

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

index

public int index(java.lang.Object atom)
Returns the index of the specified atom in this universe; if the atom is not in this universe, an IllegalArgumentException is thrown.

Returns:
this.atoms.atom
Throws:
java.lang.IllegalArgumentException - - no this.atoms.atom

iterator

public java.util.Iterator<java.lang.Object> iterator()
Returns an iterator over atoms in this universe, according to their order in the universe.

Specified by:
iterator in interface java.lang.Iterable<java.lang.Object>
Returns:
an iterator over atoms in this universe, according to their order in the universe

toString

public java.lang.String toString()
Returns a string representation of this universe.

Overrides:
toString in class java.lang.Object
Returns:
string representation of this universe.