public class BooleanFormula extends Object implements Set<BooleanTerm>, Serializable
The variable names are instances of BooleanVar
.
The group of variables that are and'ed together are terms (a.k.a. clauses),
instances of BooleanTerm
.
The group of terms that are or'ed together are the formula encapsulated by this object.
Constructor and Description |
---|
BooleanFormula()
Default constructor.
|
BooleanFormula(boolean state)
Constructs a formula that evaluates to the specified boolean state.
|
BooleanFormula(BooleanFormula other)
Copy constructor.
|
BooleanFormula(String str)
Constructs a formula who's state is given by the specified string.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(BooleanTerm booleanTerm)
Adds the term to the formula.
|
boolean |
addAll(BooleanFormula other)
Adds the terms from the specified formula to this formula
|
boolean |
addAll(Collection<? extends BooleanTerm> terms)
Adds the terms to the formula.
|
BooleanFormula |
andWith(BooleanFormula other)
Logically ands the provided terms with the terms in the formula,
replacing this formula with the result
|
void |
clear() |
boolean |
contains(Object object) |
boolean |
containsAll(Collection<?> collection) |
boolean |
equals(Object other)
Returns true if the set of terms encapsulated by this object is equal
to the set of terms of the other object.
|
int |
hashCode() |
boolean |
isEmpty() |
boolean |
isFalse()
Returns true if the formula is known to evaluate to false.
|
boolean |
isTrue()
Returns true if the formula is known to evaluate to true.
|
Iterator<BooleanTerm> |
iterator() |
boolean |
remove(Object object) |
boolean |
removeAll(Collection<?> collection) |
boolean |
removeTerms(Set<BooleanTerm> toRemove)
Removes the specified terms from the formula
|
BooleanFormula |
resolveWith(Features features)
Resolves the formula using the boolean values specified in
features . |
BooleanFormula |
resolveWith(Features features,
boolean coerceUndefinedToFalse)
Resolves the formula using the boolean values specified in
features . |
boolean |
retainAll(Collection<?> collection) |
BooleanFormula |
simplify()
Provided for backwards compatibility
|
BooleanFormula |
simplify(Map<?,?> fCache)
Returns an instance of this class which is the simplified representation of the formula
represented by this object.
|
int |
size() |
Object[] |
toArray() |
<T> T[] |
toArray(T[] array) |
String |
toString() |
public BooleanFormula()
public BooleanFormula(boolean state)
state
- The initial state of the formulapublic BooleanFormula(BooleanFormula other)
other
- The formula who's state this formula should copy.public BooleanFormula(String str)
str
- The string representation of the formulapublic BooleanFormula simplify()
public BooleanFormula simplify(Map<?,?> fCache)
This method uses the Quine-McCluskey algorithm and code described at http://en.literateprograms.org/Quine-McCluskey_algorithm_%28Java%29
fCache
- the formula cachepublic BooleanFormula resolveWith(Features features)
features
. If there are no more un-resolved variables in the
forumula, the resulting formula will be either TRUE or FALSE.features
- the values to assign to variables in the formulapublic BooleanFormula resolveWith(Features features, boolean coerceUndefinedToFalse)
features
. If there are no more un-resolved variables in the
forumula, the resulting formula will be either TRUE or FALSE.features
- the values to assign to variables in the formulacoerceUndefinedToFalse
- if true, then undefined features will be treated as falsepublic boolean addAll(BooleanFormula other)
other
- The formula who's terms are to be addedpublic BooleanFormula andWith(BooleanFormula other)
other
- the terms to and with this formulapublic boolean removeTerms(Set<BooleanTerm> toRemove)
toRemove
- The set of terms to removepublic boolean isTrue()
simplify()
.public boolean isFalse()
simplify()
.public boolean add(BooleanTerm booleanTerm)
A null term represents an expression of true and sets the formula to true (null).
add
in interface Collection<BooleanTerm>
add
in interface Set<BooleanTerm>
public boolean addAll(Collection<? extends BooleanTerm> terms)
addAll
in interface Collection<BooleanTerm>
addAll
in interface Set<BooleanTerm>
public void clear()
clear
in interface Collection<BooleanTerm>
clear
in interface Set<BooleanTerm>
public boolean contains(Object object)
contains
in interface Collection<BooleanTerm>
contains
in interface Set<BooleanTerm>
public boolean containsAll(Collection<?> collection)
containsAll
in interface Collection<BooleanTerm>
containsAll
in interface Set<BooleanTerm>
public boolean isEmpty()
isEmpty
in interface Collection<BooleanTerm>
isEmpty
in interface Set<BooleanTerm>
public Iterator<BooleanTerm> iterator()
iterator
in interface Iterable<BooleanTerm>
iterator
in interface Collection<BooleanTerm>
iterator
in interface Set<BooleanTerm>
public boolean remove(Object object)
remove
in interface Collection<BooleanTerm>
remove
in interface Set<BooleanTerm>
public boolean removeAll(Collection<?> collection)
removeAll
in interface Collection<BooleanTerm>
removeAll
in interface Set<BooleanTerm>
public boolean retainAll(Collection<?> collection)
retainAll
in interface Collection<BooleanTerm>
retainAll
in interface Set<BooleanTerm>
public int size()
size
in interface Collection<BooleanTerm>
size
in interface Set<BooleanTerm>
public Object[] toArray()
toArray
in interface Collection<BooleanTerm>
toArray
in interface Set<BooleanTerm>
public <T> T[] toArray(T[] array)
toArray
in interface Collection<BooleanTerm>
toArray
in interface Set<BooleanTerm>
public boolean equals(Object other)
simplify()
on both objects before comparing the returned objects for equality.equals
in interface Collection<BooleanTerm>
equals
in interface Set<BooleanTerm>
equals
in class Object
public int hashCode()
hashCode
in interface Collection<BooleanTerm>
hashCode
in interface Set<BooleanTerm>
hashCode
in class Object
Copyright © 2011-2015 IBM. All Rights Reserved.