Class FixTrueFalse

java.lang.Object
org.variantsync.diffdetective.util.fide.FixTrueFalse

public class FixTrueFalse extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static 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

    Fields
    Modifier and Type
    Field
    Description
    static final org.prop4j.Literal
    Constant literal representing false.
    static final List<String>
    Names of variables that we want to interpret as the constant false.
    static final org.prop4j.Literal
    Constant literal representing true.
    static final List<String>
    Names of variables that we want to interpret as the constant true.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static <T> boolean
    contains(T[] ts, Predicate<T> elem)
    Check if ts contains an element matching the predicate elem.
    EliminateTrueAndFalse(org.prop4j.Node formula)
    Replaces all literals in the given formula with the literals True and False.
    EliminateTrueAndFalseInplace(org.prop4j.Node formula)
    Same as EliminateTrueAndFalse(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 of nodes for which the predicate filter returns false.
    static boolean
    isFalse(org.prop4j.Node f)
    Returns true iff the given formula is a false literal.
    static boolean
    Returns true iff the given name represents the atomic value false.
    static boolean
    isFalseLiteral(org.prop4j.Literal l)
    Returns true iff the given literal's variable is the atomic value false.
    static boolean
    isTrue(org.prop4j.Node f)
    Returns true iff the given formula is a true literal.
    static boolean
    Returns true iff the given name represents the atomic value true.
    static boolean
    isTrueLiteral(org.prop4j.Literal l)
    Returns true iff the given literal's variable is the atomic value true.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TrueNames

      public static final List<String> TrueNames
      Names of variables that we want to interpret as the constant true.
    • FalseNames

      public static final List<String> FalseNames
      Names of variables that we want to interpret as the constant false.
    • True

      public static final org.prop4j.Literal True
      Constant literal representing true.
    • False

      public static final org.prop4j.Literal False
      Constant literal representing false.
  • Constructor Details

    • FixTrueFalse

      public FixTrueFalse()
  • Method Details

    • isTrue

      public static boolean isTrue(org.prop4j.Node f)
      Returns true iff the given formula is a true literal.
      See Also:
    • isFalse

      public static boolean isFalse(org.prop4j.Node f)
      Returns true 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 value true.
      See Also:
    • isTrueLiteral

      public static boolean isTrueLiteral(String l)
      Returns true iff the given name represents the atomic value true.
      See Also:
    • isFalseLiteral

      public static boolean isFalseLiteral(org.prop4j.Literal l)
      Returns true iff the given literal's variable is the atomic value false.
      See Also:
    • isFalseLiteral

      public static boolean isFalseLiteral(String l)
      Returns true iff the given name represents the atomic value false.
      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 of nodes for which the predicate filter returns false.
    • contains

      private static <T> boolean contains(T[] ts, Predicate<T> elem)
      Check if ts contains an element matching the predicate elem.
    • EliminateTrueAndFalse

      public static FixTrueFalse.Formula EliminateTrueAndFalse(org.prop4j.Node formula)
      Replaces all literals in the given formula with the literals True and False. This includes replacing literals representing variables with names of constants with their actual constant, for example literals with a name contained in TrueNames by True. By applying constant folding the result will be either True, 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) see EliminateTrueAndFalseInplace(org.prop4j.Node).
      Parameters:
      formula - the formula to simplify. It remains unchanged.
      Returns:
      either True, False, negations of the previous (i.e., in terms of Not or Literal), or a formula without True or False
    • EliminateTrueAndFalseInplace

      public static FixTrueFalse.Formula EliminateTrueAndFalseInplace(org.prop4j.Node formula)
      Same as EliminateTrueAndFalse(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 of Not or Literal), or a formula without True or False
      See Also:
    • EliminateTrueAndFalseInplaceRecurse

      private static org.prop4j.Node EliminateTrueAndFalseInplaceRecurse(org.prop4j.Node formula)