@API(value=INTERNAL) public class BooleanNormalizer extends Object
QueryComponent
predicates into disjunctive normal form.
The full normal form has a single Or
at the root, all of whose children are And
, none of whose
children have other Boolean operators. This is abbreviated to exclude parent Boolean nodes with only one child.
The intermediate form for the normalizer is a list of lists.
The size of a Boolean expression in disjunctive normal form (DNF) is the number of terms in the outermost
Or
[O'Donnell 2014].
The BooleanNormalizer
will not normalize a QueryComponent
if the normalized form would have a size
that exceeds the size limit. This limit is useful to avoid wastefully normalizing expressions with a very large DNF.
In some cases, such as a large expression in conjunctive normal form (CNF), attempting to normalize such an expression
will cause out-of-memory errors.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_SIZE_LIMIT
The default limit on the size of the DNF that will be produced by the normalizer.
|
Modifier and Type | Method and Description |
---|---|
static BooleanNormalizer |
getDefaultInstance()
Obtain a normalizer with the default size limit
DEFAULT_SIZE_LIMIT . |
QueryComponent |
normalize(QueryComponent predicate)
Convert the given predicate to disjunctive normal form, if necessary.
|
QueryComponent |
normalizeIfPossible(QueryComponent predicate)
Convert the given predicate to disjunctive normal form, if necessary.
|
static BooleanNormalizer |
withLimit(int sizeLimit)
Obtain a normalizer with the given size limit.
|
public static final int DEFAULT_SIZE_LIMIT
@Nonnull public static BooleanNormalizer getDefaultInstance()
DEFAULT_SIZE_LIMIT
.@Nonnull public static BooleanNormalizer withLimit(int sizeLimit)
sizeLimit
- a limit on the size of DNF that this normalizer will produce@Nullable public QueryComponent normalizeIfPossible(@Nullable QueryComponent predicate)
predicate
- the query predicate to be normalized@Nullable public QueryComponent normalize(@Nullable QueryComponent predicate)
DNFTooLargeException
.predicate
- the query predicate to be normalizedDNFTooLargeException
- if the DNF would exceed the size limit