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
Nested ClassesModifier and TypeClassDescriptionstatic classThis 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
FieldsModifier and TypeFieldDescriptionstatic final org.prop4j.LiteralConstant literal representing false.Names of variables that we want to interpret as the constant false.static final org.prop4j.LiteralConstant literal representing true.Names of variables that we want to interpret as the constant true. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> booleanCheck iftscontains an element matching the predicateelem.static FixTrueFalse.FormulaEliminateTrueAndFalse(org.prop4j.Node formula) Replaces all literals in the givenformulawith the literalsTrueandFalse.static FixTrueFalse.FormulaEliminateTrueAndFalseInplace(org.prop4j.Node formula) Same asEliminateTrueAndFalse(org.prop4j.Node)but mutates the given formula in-place.private static org.prop4j.NodeEliminateTrueAndFalseInplaceRecurse(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 ofnodesfor which the predicatefilterreturns false.static booleanisFalse(org.prop4j.Node f) Returnstrueiff the given formula is a false literal.static booleanReturns true iff the given name represents the atomic valuefalse.static booleanisFalseLiteral(org.prop4j.Literal l) Returns true iff the given literal's variable is the atomic valuefalse.static booleanisTrue(org.prop4j.Node f) Returnstrueiff the given formula is a true literal.static booleanReturns true iff the given name represents the atomic valuetrue.static booleanisTrueLiteral(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) Returnstrueiff the given formula is a true literal.- See Also:
-
isFalse
public static boolean isFalse(org.prop4j.Node f) Returnstrueiff 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 ofnodesfor which the predicatefilterreturns false. -
contains
Check iftscontains an element matching the predicateelem. -
EliminateTrueAndFalse
Replaces all literals in the givenformulawith the literalsTrueandFalse. This includes replacing literals representing variables with names of constants with their actual constant, for example literals with a name contained inTrueNamesbyTrue. 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 ofNotorLiteral), 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 ofNotorLiteral), or a formula without True or False - See Also:
-
EliminateTrueAndFalseInplaceRecurse
private static org.prop4j.Node EliminateTrueAndFalseInplaceRecurse(org.prop4j.Node formula)
-