nenok.va
Class Domain

java.lang.Object
  extended by nenok.va.Domain
All Implemented Interfaces:
Serializable, Iterable<Variable>

public class Domain
extends Object
implements Serializable, Iterable<Variable>

The domain of a valuation is a set of variables and this class offers a corresponding pre-implementation. Domains are serializable such that they can be transmitted between network hosts. Furthermore, this type is immutable for synchronization issues.

Version:
1.2
Author:
Marc Pouly
See Also:
Serialized Form

Field Summary
static Domain EMPTY
          Empty domain as a constant.
 
Constructor Summary
Domain(Collection<? extends Variable> vars)
          Constructor:
Domain(Variable... vars)
          Constructor:
 
Method Summary
 List<Variable> asList()
          Returns the current domain as a list of variables.
 boolean contains(Variable var)
          Does the current domain contain a given variable.
static Domain difference(Domain dom1, Domain dom2)
          Computes the difference of the two domains.
 boolean equals(Object o)
           
 int hashCode()
           
static Domain intersection(Domain dom1, Domain dom2)
          Computes the intersection of the two domains.
 Iterator<Variable> iterator()
           
static List<Domain> powerSet(Domain dom)
          Builds the powerset of the domain given as argument.
 int size()
           
 boolean subSetOf(Domain dom)
          Tests, if this domain is a subset of the domain given as argument, i.e. if all variables of this are contained within the argument.
 Variable[] toArray()
          Returns the current domain as an array of variables.
 String toString()
           
static Domain totalDomain(Collection<Locator> locs)
          Computes the union domain of a collection of locators.
static Domain totalDomain(Locator[] locs)
          Computes the union domain of an array of locators.
static Domain totalDomain(Valuation[] valuations)
          Computes the union domain of an array of valuations.
static Domain union(Collection<Domain> domains)
          Computes the union of a collection of domains.
static Domain union(Domain[] domains)
          Computes the union of an array of domains.
static Domain union(Domain dom1, Domain dom2)
          Computes the union of the two domains.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final Domain EMPTY
Empty domain as a constant.

Constructor Detail

Domain

public Domain(Variable... vars)
Constructor:

Parameters:
vars - An arbitrary number of variables.

Domain

public Domain(Collection<? extends Variable> vars)
Constructor:

Parameters:
vars - A collection of variables.
Method Detail

size

public int size()
Returns:
The domain's size, i.e. the number of variables in the current domain.

iterator

public Iterator<Variable> iterator()
Specified by:
iterator in interface Iterable<Variable>
Returns:
The domain's variable iterator.
See Also:
Iterable.iterator()

subSetOf

public boolean subSetOf(Domain dom)
Tests, if this domain is a subset of the domain given as argument, i.e. if all variables of this are contained within the argument.

Parameters:
dom - The domain which is a possible superset.
Returns:
true, if this is a subset of dom.

contains

public boolean contains(Variable var)
Does the current domain contain a given variable. Attention: This method is very slow - don't use it if possible.

Parameters:
var - The variable to find in the current domain.
Returns:
true, if this contains the given variable.

toArray

public Variable[] toArray()
Returns the current domain as an array of variables.

Returns:
An array containing the domain's variables.

asList

public List<Variable> asList()
Returns the current domain as a list of variables.

Returns:
A list containing the domain's variables.

equals

public boolean equals(Object o)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

toString

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

union

public static Domain union(Domain dom1,
                           Domain dom2)
Computes the union of the two domains.

Parameters:
dom1 - The first domain.
dom2 - The second domain.
Returns:
The union of dom1 and dom2.

union

public static Domain union(Domain[] domains)
Computes the union of an array of domains.

Parameters:
domains - An array of domains.
Returns:
The domain corresponding to the union of all arguments.

union

public static Domain union(Collection<Domain> domains)
Computes the union of a collection of domains.

Parameters:
domains - An collection of domains.
Returns:
The domain corresponding to the union of all arguments.

intersection

public static Domain intersection(Domain dom1,
                                  Domain dom2)
Computes the intersection of the two domains.

Parameters:
dom1 - The first domain.
dom2 - The second domain.
Returns:
The intersection of dom1 and dom2.

difference

public static Domain difference(Domain dom1,
                                Domain dom2)
Computes the difference of the two domains.

Parameters:
dom1 - The first domain.
dom2 - The second domain.
Returns:
The difference dom1 / dom2.

totalDomain

public static Domain totalDomain(Valuation[] valuations)
Computes the union domain of an array of valuations.

Parameters:
valuations - The array of valuations.
Returns:
The domain corresponding to the union of all valuation's labels.

totalDomain

public static Domain totalDomain(Locator[] locs)
Computes the union domain of an array of locators.

Parameters:
locs - The array of locators.
Returns:
The domain corresponding to the union of all locators' domain.

totalDomain

public static Domain totalDomain(Collection<Locator> locs)
Computes the union domain of a collection of locators.

Parameters:
locs - The collection of locators.
Returns:
The domain corresponding to the union of all locators' domains.

powerSet

public static List<Domain> powerSet(Domain dom)
Builds the powerset of the domain given as argument.

Parameters:
dom - The domain whose powerset shall be built.
Returns:
The powerset of the given domain.