Class UniLeftHandSide<A>

  • Type Parameters:
    A - generic type of the resulting variable

    public final class UniLeftHandSide<A>
    extends Object
    Represents the left-hand side of a Drools rule, the result of which is a single variable. The simplest variant of such rule, with no filters or groupBys applied, would look like this in equivalent DRL:
     
      rule "Simplest univariate rule"
      when
          $a: Something()
      then
          // Do something with the $a variable.
      end
     
     
    Left-hand side is that part of the rule between the "when" and "then" keywords. The part between the "then" and "end" keywords is called the consequence of the rule, and this class does not represent it. It can be created by calling andTerminate(). There are also more complex variants of rules that still result in just one variable:
     
      rule "Complex univariate rule"
      when
          $accumulateResult: Collection() from accumulate(
              ...
          )
          $a: Object() from $accumulateResult
          exists Something()
      then
          // Do something with the $a variable.
      end
     
     
    To create the simplest possible variant, call UniLeftHandSide(Class, DroolsVariableFactory). Further specializations can be introduced by calling builder methods such as andFilter(Predicate). These builder methods will always return a new instance of AbstractLeftHandSide, as these are immutable. Some builder methods, such as andJoin(UniLeftHandSide, BiJoiner), will return an instance of BiLeftHandSide (TriLeftHandSide, ...), as that particular operation will increase the cardinality of the parent constraint stream.
    • Method Detail

      • getPatternVariableA

        public PatternVariable<A,​?,​?> getPatternVariableA()
      • andTerminate

        public <Solution_> RuleBuilder<Solution_> andTerminate()
      • getConstraintType

        protected static org.drools.model.Index.ConstraintType getConstraintType​(JoinerType type)
      • joinViewItemsWithLogicalAnd

        protected static org.drools.model.view.ViewItem<?> joinViewItemsWithLogicalAnd​(PatternVariable<?,​?,​?>... patternVariables)
      • mergeViewItems

        protected static List<org.drools.model.view.ViewItem<?>> mergeViewItems​(PatternVariable<?,​?,​?>... patternVariables)
      • decompose

        protected static <A,​B> org.optaplanner.core.impl.score.stream.drools.common.IndirectPatternVariable<B,​BiTuple<A,​B>> decompose​(org.drools.model.Variable<BiTuple<A,​B>> primaryVariable,
                                                                                                                                                        org.drools.model.view.ViewItem<?> prerequisitePattern,
                                                                                                                                                        org.drools.model.Variable<A> boundVarA,
                                                                                                                                                        org.drools.model.Variable<B> boundVarB)
        Create an IndirectPatternVariable on BiTuple with pre-made bindings for its components variables.
        Type Parameters:
        A - generic type of the first bound variable
        B - generic type of the second bound variable
        Parameters:
        primaryVariable - never null
        prerequisitePattern - never null, pattern required to construct the variable
        boundVarA - never null, BiTuple.a
        boundVarB - never null, BiTuple.b
        Returns:
        never null
      • decomposeWithAccumulate

        protected static <A,​B,​C> org.optaplanner.core.impl.score.stream.drools.common.DirectPatternVariable<C> decomposeWithAccumulate​(org.drools.model.Variable<BiTuple<A,​B>> primaryVariable,
                                                                                                                                                   org.drools.model.view.ViewItem<?> prerequisitePattern,
                                                                                                                                                   org.drools.model.Variable<A> boundVarA,
                                                                                                                                                   org.drools.model.Variable<B> boundVarB,
                                                                                                                                                   org.drools.model.Variable<C> accumulateOutput)
        Create a DirectPatternVariable on BiTuple with pre-made bindings for its components variables and one accumulate output variable.
        Type Parameters:
        A - generic type of the first bound variable
        B - generic type of the second bound variable
        C - generic type of the accumulate output variable
        Parameters:
        primaryVariable - never null
        prerequisitePattern - never null, pattern required to construct the variable
        boundVarA - never null, TriTuple.a
        boundVarB - never null, TriTuple.b
        accumulateOutput - never null, output of the accumulate function
        Returns:
        never null
      • decompose

        protected static <A,​B,​C> org.optaplanner.core.impl.score.stream.drools.common.IndirectPatternVariable<C,​TriTuple<A,​B,​C>> decompose​(org.drools.model.Variable<TriTuple<A,​B,​C>> primaryVariable,
                                                                                                                                                                         org.drools.model.view.ViewItem<?> prerequisitePattern,
                                                                                                                                                                         org.drools.model.Variable<A> boundVarA,
                                                                                                                                                                         org.drools.model.Variable<B> boundVarB,
                                                                                                                                                                         org.drools.model.Variable<C> boundVarC)
        Create an IndirectPatternVariable on TriTuple with pre-made bindings for its components variables.
        Type Parameters:
        A - generic type of the first bound variable
        B - generic type of the second bound variable
        C - generic type of the third bound variable
        Parameters:
        primaryVariable - never null
        prerequisitePattern - never null, pattern required to construct the variable
        boundVarA - never null, TriTuple.a
        boundVarB - never null, TriTuple.b
        boundVarC - never null, TriTuple.c
        Returns:
        never null
      • decompose

        protected static <A,​B,​C,​D> org.optaplanner.core.impl.score.stream.drools.common.IndirectPatternVariable<D,​QuadTuple<A,​B,​C,​D>> decompose​(org.drools.model.Variable<QuadTuple<A,​B,​C,​D>> primaryVariable,
                                                                                                                                                                                          org.drools.model.view.ViewItem<?> prerequisitePattern,
                                                                                                                                                                                          org.drools.model.Variable<A> boundVarA,
                                                                                                                                                                                          org.drools.model.Variable<B> boundVarB,
                                                                                                                                                                                          org.drools.model.Variable<C> boundVarC,
                                                                                                                                                                                          org.drools.model.Variable<D> boundVarD)
        Create an IndirectPatternVariable on QuadTuple with pre-made bindings for its components variables.
        Type Parameters:
        A - generic type of the first bound variable
        B - generic type of the second bound variable
        C - generic type of the third bound variable
        D - generic type of the fourth bound variable
        Parameters:
        primaryVariable - never null
        prerequisitePattern - never null, pattern required to construct the variable
        boundVarA - never null, QuadTuple.a
        boundVarB - never null, QuadTuple.b
        boundVarC - never null, QuadTuple.c
        boundVarD - never null, QuadTuple.d
        Returns:
        never null
      • decomposeWithAccumulate

        protected static <A,​B,​C,​D> org.optaplanner.core.impl.score.stream.drools.common.DirectPatternVariable<D> decomposeWithAccumulate​(org.drools.model.Variable<TriTuple<A,​B,​C>> primaryVariable,
                                                                                                                                                           org.drools.model.view.ViewItem<?> prerequisitePattern,
                                                                                                                                                           org.drools.model.Variable<A> boundVarA,
                                                                                                                                                           org.drools.model.Variable<B> boundVarB,
                                                                                                                                                           org.drools.model.Variable<C> boundVarC,
                                                                                                                                                           org.drools.model.Variable<D> accumulateOutput)
        Create a DirectPatternVariable on TriTuple with pre-made bindings for its components variables and one accumulate output variable.
        Type Parameters:
        A - generic type of the first bound variable
        B - generic type of the second bound variable
        C - generic type of the third bound variable
        D - generic type of the accumulate output variable
        Parameters:
        primaryVariable - never null
        prerequisitePattern - never null, pattern required to construct the variable
        boundVarA - never null, TriTuple.a
        boundVarB - never null, TriTuple.b
        boundVarC - never null, TriTuple.c
        accumulateOutput - never null, output of the accumulate function
        Returns:
        never null
      • buildAccumulate

        protected static org.drools.model.view.ViewItem<?> buildAccumulate​(org.drools.model.view.ViewItem<?> innerAccumulatePattern,
                                                                           org.drools.model.functions.accumulate.AccumulateFunction... accFunctions)