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<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<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.
    `abstract DroolsPatternBuilder<Object>` | `getPrimaryPattern()` Returns the pattern that the subsequent streams may further expand.
    `abstract List<org.drools.model.RuleItemBuilder<?>>` | `getSupportingRuleItems()` Every other pattern necessary for the `getPrimaryPattern()` to function properly within the Drools rule's left-hand side.
    `LongSupplier` | `getVariableIdSupplier()`
    `List<org.drools.model.RuleItemBuilder<?>>` | `rebuildSupportingRuleItems(org.drools.model.RuleItemBuilder<?>... toAdd)` Takes `getSupportingRuleItems()`, puts them into a new `List`, and adds additional `RuleItemBuilder`s after it.

    - ### 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<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<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.

    - #### rebuildSupportingRuleItems

          public final List<org.drools.model.RuleItemBuilder<?>> rebuildSupportingRuleItems(org.drools.model.RuleItemBuilder<?>... toAdd)

      Takes `getSupportingRuleItems()`, puts them into a new `List`, and adds additional `RuleItemBuilder`s after it.
      Parameters:
        `toAdd` - the additional items to add
      Returns:
        new list containing both the existing supporting rule items and the new ones

    - #### 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

    - #### getSupportingRuleItems

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

      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 supporting `RuleItemBuilder`, the one representing $a1.
      Returns:
        all supporting rule items as defined, in the correct order

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