Class FixTrueFalse
java.lang.Object
org.variantsync.diffdetective.util.fide.FixTrueFalse
Class to fix bugs related to
True
and False
of FeatureIDE.
See: FeatureIDE Issue 1111
See: FeatureIDE Issue 1333
This class contains constants for representing atomic values true and false in formulas
as well as a conversion method for parsing certain feature names to true and false, respectively.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
This class is a witness that a formula had its true and false constants eliminated or is just such a constant (and nothing else except from perhaps negations). -
Field Summary
Modifier and TypeFieldDescriptionstatic final org.prop4j.Literal
Constant literal representing false.Names of variables that we want to interpret as the constant false.static final org.prop4j.Literal
Constant literal representing true.Names of variables that we want to interpret as the constant true. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> boolean
Check ifts
contains an element matching the predicateelem
.static FixTrueFalse.Formula
EliminateTrueAndFalse
(org.prop4j.Node formula) Replaces all literals in the givenformula
with the literalsTrue
andFalse
.static FixTrueFalse.Formula
EliminateTrueAndFalseInplace
(org.prop4j.Node formula) Same asEliminateTrueAndFalse(org.prop4j.Node)
but mutates the given formula in-place.private static org.prop4j.Node
EliminateTrueAndFalseInplaceRecurse
(org.prop4j.Node formula) private static org.prop4j.Node[]
filterMatches
(org.prop4j.Node[] nodes, Predicate<org.prop4j.Node> filter) Return a new array only containing elements ofnodes
for which the predicatefilter
returns false.static boolean
isFalse
(org.prop4j.Node f) Returnstrue
iff the given formula is a false literal.static boolean
Returns true iff the given name represents the atomic valuefalse
.static boolean
isFalseLiteral
(org.prop4j.Literal l) Returns true iff the given literal's variable is the atomic valuefalse
.static boolean
isTrue
(org.prop4j.Node f) Returnstrue
iff the given formula is a true literal.static boolean
Returns true iff the given name represents the atomic valuetrue
.static boolean
isTrueLiteral
(org.prop4j.Literal l) Returns true iff the given literal's variable is the atomic valuetrue
.
-
Field Details
-
TrueNames
Names of variables that we want to interpret as the constant true. -
FalseNames
Names of variables that we want to interpret as the constant false. -
True
public static final org.prop4j.Literal TrueConstant literal representing true. -
False
public static final org.prop4j.Literal FalseConstant literal representing false.
-
-
Constructor Details
-
FixTrueFalse
public FixTrueFalse()
-
-
Method Details
-
isTrue
public static boolean isTrue(org.prop4j.Node f) Returnstrue
iff the given formula is a true literal.- See Also:
-
isFalse
public static boolean isFalse(org.prop4j.Node f) Returnstrue
iff the given formula is a false literal.- See Also:
-
isTrueLiteral
public static boolean isTrueLiteral(org.prop4j.Literal l) Returns true iff the given literal's variable is the atomic valuetrue
.- See Also:
-
isTrueLiteral
Returns true iff the given name represents the atomic valuetrue
.- See Also:
-
isFalseLiteral
public static boolean isFalseLiteral(org.prop4j.Literal l) Returns true iff the given literal's variable is the atomic valuefalse
.- See Also:
-
isFalseLiteral
Returns true iff the given name represents the atomic valuefalse
.- See Also:
-
filterMatches
private static org.prop4j.Node[] filterMatches(org.prop4j.Node[] nodes, Predicate<org.prop4j.Node> filter) Return a new array only containing elements ofnodes
for which the predicatefilter
returns false. -
contains
Check ifts
contains an element matching the predicateelem
. -
EliminateTrueAndFalse
Replaces all literals in the givenformula
with the literalsTrue
andFalse
. This includes replacing literals representing variables with names of constants with their actual constant, for example literals with a name contained inTrueNames
byTrue
. By applying constant folding the result will be eitherTrue
,False
, or a formula that does not contain any True or False nodes. For an impure, in-place version of this method (which is likely more performant) seeEliminateTrueAndFalseInplace(org.prop4j.Node)
.- Parameters:
formula
- the formula to simplify. It remains unchanged.- Returns:
- either
True
,False
, negations of the previous (i.e., in terms ofNot
orLiteral
), or a formula without True or False
-
EliminateTrueAndFalseInplace
Same asEliminateTrueAndFalse(org.prop4j.Node)
but mutates the given formula in-place. Thus, the given formula should not be used after invoking this method as it might be corrupted. Instead, the returned node should be used.- Parameters:
formula
- the formula to transform- Returns:
- either
True
,False
, negations of the previous (i.e., in terms ofNot
orLiteral
), or a formula without True or False - See Also:
-
EliminateTrueAndFalseInplaceRecurse
private static org.prop4j.Node EliminateTrueAndFalseInplaceRecurse(org.prop4j.Node formula)
-