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

## Interface DroolsMetadata<LogicalFactType,GenuineFactType>

- Type Parameters:
    `LogicalFactType` - The actual type of the fact in the current rule.
    `GenuineFactType` - The original type of the fact, in the original genuine rule.
  All Known Implementing Classes:
    DroolsGenuineMetadata, DroolsInferredMetadata

      public interface DroolsMetadata<LogicalFactType,GenuineFactType>

  Represents a variable on the left-hand side of a rule. This variable can either be genuine or logical.
  Genuine variables look like this:
    $a: SomeFact()
    $b: SomeOtherFact()
  Logical variables look like this:
    LogicalTuple($a: getItem(0), $b: getItem(1))
  Genuine variables become logical variables through an operation of logical insertion, which might look like this:

           rule "Rule with genuine facts"
           when
                $a: SomeFact()
                $b: SomeOtherFact()
           then
                insertLogical(new LogicalTuple($a, $b));
           end

           rule "Rule with an inferred fact"
           when
                LogicalTuple($a: getItem(0), $b: getItem(1))
           then
                // some consequence
           end

  This class is an abstraction, allowing code to read variables of both types.

- - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `<any>` | `buildPattern()` A pattern is a way of accessing the variable in Drools.
    `GenuineFactType` | `extract(LogicalFactType container)` Extract variable value from the rule.
    `<any>` | `getVariableDeclaration()`
    `static <A> DroolsGenuineMetadata<A>` | `ofGenuine(<any> variableDeclaration)`
    `static <A> DroolsInferredMetadata<A>` | `ofInferred(<any> variableDeclaration, Supplier<<any>> patternBuilder)`
    `static <A> DroolsInferredMetadata<A>` | `ofInferred(<any> variableDeclaration, Supplier<<any>> patternBuilder, int itemId)`
    `DroolsMetadata<LogicalFactType,GenuineFactType>` | `substitute(Supplier<<any>> patternBuilder)` Create new `DroolsMetadata`, where its pattern will be different.

- - ### Method Detail

    - #### ofInferred

          static <A> DroolsInferredMetadata<A> ofInferred(<any> variableDeclaration,
                                                          Supplier<<any>> patternBuilder)

    - #### ofInferred

          static <A> DroolsInferredMetadata<A> ofInferred(<any> variableDeclaration,
                                                          Supplier<<any>> patternBuilder,
                                                          int itemId)

    - #### ofGenuine

          static <A> DroolsGenuineMetadata<A> ofGenuine(<any> variableDeclaration)

    - #### extract

          GenuineFactType extract(LogicalFactType container)

      Extract variable value from the rule. For genuine variables, this will be equivalent to `Function.identity()`. For inferred variables, this will refer to the `DroolsLogicalTuple.getItem(int)`.
      Parameters:
        `container` - the variable from Drools on which to operate
      Returns:
        value of the variable

    - #### getVariableDeclaration

          <any> getVariableDeclaration()

    - #### buildPattern

          <any> buildPattern()

      A pattern is a way of accessing the variable in Drools. In some rules, patterns may be reused for several different constructs. Drools does not support reuse of pattern instances for different uses, and therefore we must create new ones every time we want to use them.
      Returns:
        pattern to give access to the variable

    - #### substitute

          DroolsMetadata<LogicalFactType,GenuineFactType> substitute(Supplier<<any>> patternBuilder)

      Create new `DroolsMetadata`, where its pattern will be different.
      Parameters:
        `patternBuilder` - the new pattern to be returned by `buildPattern()`. Typically reuses the parent pattern with some modifications.
      Returns:
        New instance of `DroolsMetadata`.

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