Class BooleanCondition
- java.lang.Object
-
- com.google.gerrit.extensions.conditions.BooleanCondition
-
- Direct Known Subclasses:
PrivateInternals_BooleanCondition.SubclassOnlyInCoreServer
public abstract class BooleanCondition extends Object
Delayed evaluation of a boolean condition.
-
-
Field Summary
Fields Modifier and Type Field Description static BooleanCondition
FALSE
static BooleanCondition
TRUE
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static BooleanCondition
and(boolean a, BooleanCondition b)
static BooleanCondition
and(BooleanCondition a, BooleanCondition b)
abstract <T> Iterable<T>
children(Class<T> type)
Recursively collect all children of typetype
.protected abstract boolean
evaluatesTrivially()
Check if the condition evaluates to eithertrue
orfalse
without providing additional information to the evaluation tree, e.g.static BooleanCondition
not(BooleanCondition bc)
static BooleanCondition
or(boolean a, BooleanCondition b)
static BooleanCondition
or(BooleanCondition a, BooleanCondition b)
abstract BooleanCondition
reduce()
Reduce evaluation tree by cutting off branches that evaluate trivially and replacing them with a leave note corresponding to the value the branch evaluated to.abstract boolean
value()
static BooleanCondition
valueOf(boolean a)
-
-
-
Field Detail
-
TRUE
public static final BooleanCondition TRUE
-
FALSE
public static final BooleanCondition FALSE
-
-
Method Detail
-
valueOf
public static BooleanCondition valueOf(boolean a)
-
and
public static BooleanCondition and(BooleanCondition a, BooleanCondition b)
-
and
public static BooleanCondition and(boolean a, BooleanCondition b)
-
or
public static BooleanCondition or(BooleanCondition a, BooleanCondition b)
-
or
public static BooleanCondition or(boolean a, BooleanCondition b)
-
not
public static BooleanCondition not(BooleanCondition bc)
-
value
public abstract boolean value()
- Returns:
- evaluate the condition and return its value.
-
children
public abstract <T> Iterable<T> children(Class<T> type)
Recursively collect all children of typetype
.- Parameters:
type
- implementation type of the conditions to collect and return.- Returns:
- non-null, unmodifiable iteration of children of type
type
.
-
reduce
public abstract BooleanCondition reduce()
Reduce evaluation tree by cutting off branches that evaluate trivially and replacing them with a leave note corresponding to the value the branch evaluated to.Example 1 (T=True, F=False, C=non-trivial check): OR / \ => T C T Example 2 (cuts off a not-trivial check): AND / \ => F C F Example 3: AND / \ => F T F
There is no guarantee that the resulting tree is minimal. The only guarantee made is that branches that evaluate trivially will be cut off and replaced by primitive values.
-
evaluatesTrivially
protected abstract boolean evaluatesTrivially()
Check if the condition evaluates to eithertrue
orfalse
without providing additional information to the evaluation tree, e.g. through checks to a remote service such asPermissionBackend
.In this case, the tree can be reduced to skip all non-trivial checks resulting in a performance gain.
-
-