org.optaplanner.core.impl.score.stream.drools.common

## Class DroolsRuleStructure

- java.lang.Object
- - org.optaplanner.core.impl.score.stream.drools.common.DroolsRuleStructure

- Direct Known Subclasses:
    DroolsBiRuleStructure, DroolsQuadRuleStructure, DroolsTriRuleStructure, DroolsUniRuleStructure

      public abstract class DroolsRuleStructure
      extends Object

  Represents the left-hand side of a Drools rule.

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `DroolsRuleStructure(LongSupplier variableIdSupplier)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `<X> org.drools.model.Variable<? extends X>` | `createVariable(Class<X> clz, String name)` Declare a new `Variable` in this rule, with a given name and no declared source.
    `<X> org.drools.model.Variable<? extends X>` | `createVariable(Class<X> clz, String name, org.drools.model.DeclarationSource source)` Declare a new `Variable` in this rule, with a given name and a declaration source.
    `<X> org.drools.model.Variable<X>` | `createVariable(String name)` Declares a new `Object`-typed variable, see `createVariable(Class, String, DeclarationSource)` for details.
    `<X> org.drools.model.Variable<X>` | `createVariable(String name, org.drools.model.DeclarationSource source)` Declares a new `Object`-typed variable, see `createVariable(Class, String)` for details.
    `List<org.drools.model.RuleItemBuilder<?>>` | `finish(org.drools.model.consequences.ConsequenceBuilder.AbstractValidBuilder<?> consequence)`
    `abstract List<org.drools.model.RuleItemBuilder<?>>` | `getClosedRuleItems()`
    `abstract List<org.drools.model.RuleItemBuilder<?>>` | `getOpenRuleItems()` Every other pattern necessary for the `getPrimaryPattern()` to function properly within the Drools rule's left-hand side.
    `abstract DroolsPatternBuilder<Object>` | `getPrimaryPattern()` Returns the pattern that the subsequent streams may further expand.
    `LongSupplier` | `getVariableIdSupplier()`
    `<NewA> DroolsUniRuleStructure<NewA>` | `recollect(org.drools.model.Variable<NewA> newA, org.drools.model.view.ViewItem<?> accumulatePattern)`
    `<NewA> DroolsUniRuleStructure<NewA>` | `regroup(org.drools.model.Variable<Set<NewA>> newASource, org.drools.model.PatternDSL.PatternDef<Set<NewA>> collectPattern, org.drools.model.view.ViewItem<?> accumulatePattern)`
    `<NewA,NewB> DroolsBiRuleStructure<NewA,NewB>` | `regroupBi(org.drools.model.Variable<Set<BiTuple<NewA,NewB>>> newSource, org.drools.model.PatternDSL.PatternDef<Set<BiTuple<NewA,NewB>>> collectPattern, org.drools.model.view.ViewItem<?> accumulatePattern)`
    `<NewA,NewB,NewC,NewD> DroolsQuadRuleStructure<NewA,NewB,NewC,NewD>` | `regroupBiToQuad(org.drools.model.Variable<Set<QuadTuple<NewA,NewB,NewC,NewD>>> newSource, org.drools.model.PatternDSL.PatternDef<Set<QuadTuple<NewA,NewB,NewC,NewD>>> collectPattern, org.drools.model.view.ViewItem<?> accumulatePattern)`
    `<NewA,NewB,NewC> DroolsTriRuleStructure<NewA,NewB,NewC>` | `regroupBiToTri(org.drools.model.Variable<Set<TriTuple<NewA,NewB,NewC>>> newSource, org.drools.model.PatternDSL.PatternDef<Set<TriTuple<NewA,NewB,NewC>>> collectPattern, org.drools.model.view.ViewItem<?> accumulatePattern)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DroolsRuleStructure

          protected DroolsRuleStructure(LongSupplier variableIdSupplier)

  - ### Method Detail

    - #### createVariable

          public final <X> org.drools.model.Variable<? extends X> createVariable(Class<X> clz,
                                                                                 String name)

      Declare a new `Variable` in this rule, with a given name and no declared source. Delegates to `DSL.declarationOf(Class, String)`. Creating variables via this method guarantees unique variable name within the context of a rule through the use of `DroolsConstraintFactory.getVariableIdSupplier()`.
      Type Parameters:
        `X` - Generic type of the variable.
      Parameters:
        `clz` - type of the variable. Using `Object` will work in all cases, but Drools will spend unnecessary amount of time looking up applicable instances of that variable, as it has to traverse instances of all types in the working memory. Therefore, it is desirable to be as specific as possible.
        `name` - name of the variable, mostly useful for debugging purposes. Will be decorated by a pseudo-random numeric identifier to prevent multiple variables of the same name to exist within left-hand side of a single rule.
      Returns:
        new variable declaration, not yet bound to anything

    - #### createVariable

          public final <X> org.drools.model.Variable<? extends X> createVariable(Class<X> clz,
                                                                                 String name,
                                                                                 org.drools.model.DeclarationSource source)

      Declare a new `Variable` in this rule, with a given name and a declaration source. Delegates to `DSL.declarationOf(Class, String, DeclarationSource)`. Creating variables via this method guarantees unique variable names within the context of a rule through the use of `DroolsConstraintFactory.getVariableIdSupplier()`.
      Type Parameters:
        `X` - Generic type of the variable.
      Parameters:
        `clz` - type of the variable. Using `Object` will work in all cases, but Drools will spend unnecessary amount of time looking up applicable instances of that variable, as it has to traverse instances of all types in the working memory. Therefore, it is desirable to be as specific as possible.
        `name` - name of the variable, mostly useful for debugging purposes. Will be decorated by a pseudo-random numeric identifier to prevent multiple variables of the same name to exist within left-hand side of a single rule.
        `source` - declaration source of the variable
      Returns:
        new variable declaration, not yet bound to anything

    - #### createVariable

          public final <X> org.drools.model.Variable<X> createVariable(String name)

      Declares a new `Object`-typed variable, see `createVariable(Class, String, DeclarationSource)` for details.

    - #### createVariable

          public final <X> org.drools.model.Variable<X> createVariable(String name,
                                                                       org.drools.model.DeclarationSource source)

      Declares a new `Object`-typed variable, see `createVariable(Class, String)` for details.

    - #### finish

          public final List<org.drools.model.RuleItemBuilder<?>> finish(org.drools.model.consequences.ConsequenceBuilder.AbstractValidBuilder<?> consequence)

    - #### getVariableIdSupplier

          public LongSupplier getVariableIdSupplier()

    - #### getPrimaryPattern

          public abstract DroolsPatternBuilder<Object> getPrimaryPattern()

      Returns the pattern that the subsequent streams may further expand. Consider the following left-hand side of a Drools rule:

               $a1: A()
               $a2: A(this != $a1)

      The primary pattern would be the latter one ($a2), as that is the pattern you would use to further expand your output in both $a1 and $a2.
      Returns:
        the primary pattern as defined

    - #### getOpenRuleItems

          public abstract List<org.drools.model.RuleItemBuilder<?>> getOpenRuleItems()

      Every other pattern necessary for the `getPrimaryPattern()` to function properly within the Drools rule's left-hand side. In the example rule (see `getPrimaryPattern()`, this method would return one and only open `RuleItemBuilder`, the one representing $a1.
      Returns:
        all open rule items as defined, in the correct order

    - #### getClosedRuleItems

          public abstract List<org.drools.model.RuleItemBuilder<?>> getClosedRuleItems()

    - #### recollect

          public <NewA> DroolsUniRuleStructure<NewA> recollect(org.drools.model.Variable<NewA> newA,
                                                               org.drools.model.view.ViewItem<?> accumulatePattern)

    - #### regroup

          public <NewA> DroolsUniRuleStructure<NewA> regroup(org.drools.model.Variable<Set<NewA>> newASource,
                                                             org.drools.model.PatternDSL.PatternDef<Set<NewA>> collectPattern,
                                                             org.drools.model.view.ViewItem<?> accumulatePattern)

    - #### regroupBi

          public <NewA,NewB> DroolsBiRuleStructure<NewA,NewB> regroupBi(org.drools.model.Variable<Set<BiTuple<NewA,NewB>>> newSource,
                                                                        org.drools.model.PatternDSL.PatternDef<Set<BiTuple<NewA,NewB>>> collectPattern,
                                                                        org.drools.model.view.ViewItem<?> accumulatePattern)

    - #### regroupBiToTri

          public <NewA,NewB,NewC> DroolsTriRuleStructure<NewA,NewB,NewC> regroupBiToTri(org.drools.model.Variable<Set<TriTuple<NewA,NewB,NewC>>> newSource,
                                                                                        org.drools.model.PatternDSL.PatternDef<Set<TriTuple<NewA,NewB,NewC>>> collectPattern,
                                                                                        org.drools.model.view.ViewItem<?> accumulatePattern)

    - #### regroupBiToQuad

          public <NewA,NewB,NewC,NewD> DroolsQuadRuleStructure<NewA,NewB,NewC,NewD> regroupBiToQuad(org.drools.model.Variable<Set<QuadTuple<NewA,NewB,NewC,NewD>>> newSource,
                                                                                                    org.drools.model.PatternDSL.PatternDef<Set<QuadTuple<NewA,NewB,NewC,NewD>>> collectPattern,
                                                                                                    org.drools.model.view.ViewItem<?> accumulatePattern)

Copyright © 2006–2020 JBoss by Red Hat. All rights reserved.