Class Domain

java.lang.Object
org.clafer.domain.Domain
Direct Known Subclasses:
BoolDomain

public class Domain extends Object
Immutable domain over integers. Internally stored as a list of (low, high) disjoint pairs of regions.
Author:
jimmy
  • Field Details

  • Constructor Details

    • Domain

      protected Domain(int... bounds)
      Parameters:
      bounds - sorted, unique, and immutable integers
  • Method Details

    • boundDomain

      public static Domain boundDomain(int low, int high)
    • constantDomain

      public static Domain constantDomain(int value)
    • enumDomain

      public static Domain enumDomain(int... values)
    • enumDomain

      public static Domain enumDomain(gnu.trove.set.TIntSet values)
    • enumDomain

      public static Domain enumDomain(IntStream values)
    • isBounded

      public boolean isBounded()
      Checks if this domain is defined as a lower and upper bound. If the domain is bounded then it contains every value between its lower and upper bound.
      Returns:
      true if and only if this domain is a single contiguous region, false otherwise
    • contains

      public boolean contains(int value)
      Checks if a value is within this domain.
      Parameters:
      value - test this value
      Returns:
      true if and only if this domain contains the value, false otherwise
    • containsAll

      public boolean containsAll(gnu.trove.TIntCollection values)
    • containsAll

      public boolean containsAll(int[] values)
    • containsAll

      public boolean containsAll(int low, int high)
    • containsAny

      public boolean containsAny(gnu.trove.TIntCollection values)
    • containsAny

      public boolean containsAny(int[] values)
    • containsAny

      public boolean containsAny(int low, int high)
    • getLowBound

      public int getLowBound()
      Returns the smallest integer contained in this domain. Undefined if this domain is empty.
      Returns:
      the smallest integer contained in this domain
    • getHighBound

      public int getHighBound()
      Returns the largest integer contained in this domain. Undefined if this domain is empty.
      Returns:
      the largest integer contained in this domain
    • isEmpty

      public boolean isEmpty()
      Checks if this domain contains no values.
      Returns:
      true if and only if the size of this domain is zero, false otherwise
    • isConstant

      public boolean isConstant()
      Checks if this domain contains a single value.
      Returns:
      true if and only if the size of this domain is one, false otherwise
    • size

      public int size()
      Returns how many values are contained in this domain.
      Returns:
      the size of this domain
    • isSubsetOf

      public boolean isSubsetOf(Domain superset)
      Check if this domain is a (non-strict) subset of another domain.
      Parameters:
      superset -
      Returns:
      true if and only if this domain is a subset of superset, false otherwise
    • isSupersetOf

      public boolean isSupersetOf(Domain subset)
    • intersects

      public boolean intersects(Domain other)
      Check if this domain intersects another domain.
      Parameters:
      other -
      Returns:
      true if and only if this domain is intersects other, false otherwise
    • insert

      public Domain insert(int value)
      Add an element into this domain.
      Parameters:
      value -
      Returns:
      this.union({value})
    • remove

      public Domain remove(int value)
      Remove an element from this domain.
      Parameters:
      value -
      Returns:
      this.difference({value})
    • removeAll

      public Domain removeAll(IntPredicate predicate)
      Remove all elements from this domain where the predicate evaluates to true.
      Parameters:
      predicate -
      Returns:
      a subset of this domain where the predicate evaluates to false.
    • retainAll

      public Domain retainAll(IntPredicate predicate)
      Retains all elements from this domain where the predicate evaluates to true.
      Parameters:
      predicate -
      Returns:
      a subset of this domain where the predicate evaluates to true.
    • boundLow

      public Domain boundLow(int low)
      Remove all elements less than the bound from this domain.
      Parameters:
      low -
      Returns:
      this.intersection({low, low + 1, ...})
    • boundHigh

      public Domain boundHigh(int high)
      Remove all elements greater than the bound from this domain.
      Parameters:
      high -
      Returns:
      this.intersection({high, high - 1, ...})
    • boundBetween

      public Domain boundBetween(int low, int high)
      Remove all elements less than the low bound or greater than the high bound from this domain.
      Parameters:
      low -
      high -
      Returns:
      invalid @code
      {@code this.intersection({low, low + 1, ..., high})
    • minus

      public Domain minus()
    • difference

      public Domain difference(Domain other)
      Subtract this domain with the other domain.
      Parameters:
      other -
      Returns:
      the difference of this domain with the other domain
    • intersection

      public Domain intersection(Domain other)
      Intersect this domain with the other domain.
      Parameters:
      other -
      Returns:
      the intersection of this domain with the other domain
    • union

      public Domain union(Domain other)
      Union this domain with the other domain.
      Parameters:
      other -
      Returns:
      the union of this domain with the other domain
    • offset

      public Domain offset(int c)
      Shift the elements in this domain.
      Parameters:
      c -
      Returns:
      the shifted domain
    • add

      public Domain add(Domain other)
    • getValues

      public int[] getValues()
      Returns all the values contained in this domain.
      Returns:
      values contained in this domain
    • forEach

      public void forEach(IntConsumer action)
      Perform the action for every value in this domain in increasing order.
      Parameters:
      action - the action to perform
    • iterator

      Iterate over the domain in increasing order.
      Returns:
      an iterator over the values in this domain in increasing order
    • iterator

      public PrimitiveIterator.OfInt iterator(boolean increasing)
      Iterate over the domain in the specified order.
      Parameters:
      increasing - increasing or decreasing order
      Returns:
      an iterator over the values in this domain in the order specified
    • stream

      public IntStream stream()
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object