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
    --- | ---
    `org.drools.model.PatternDSL.PatternDef<LogicalFactType>` | `buildPattern()` A pattern is a way of accessing the variable in Drools.
    `GenuineFactType` | `extract(LogicalFactType container)` Extract variable value from the rule.
    `org.drools.model.Declaration<LogicalFactType>` | `getVariableDeclaration()`
    `static <A> DroolsGenuineMetadata<A>` | `ofGenuine(org.drools.model.Declaration<A> variableDeclaration)`
    `static <A> DroolsInferredMetadata<A>` | `ofInferred(org.drools.model.Declaration<DroolsLogicalTuple> variableDeclaration, Supplier<org.drools.model.PatternDSL.PatternDef<DroolsLogicalTuple>> patternBuilder)`
    `static <A> DroolsInferredMetadata<A>` | `ofInferred(org.drools.model.Declaration<DroolsLogicalTuple> variableDeclaration, Supplier<org.drools.model.PatternDSL.PatternDef<DroolsLogicalTuple>> patternBuilder, int itemId)`
    `DroolsMetadata<LogicalFactType,GenuineFactType>` | `substitute(Supplier<org.drools.model.PatternDSL.PatternDef<LogicalFactType>> patternBuilder)` Create new `DroolsMetadata`, where its pattern will be different.

- - ### Method Detail

    - #### ofInferred

          static <A> DroolsInferredMetadata<A> ofInferred(org.drools.model.Declaration<DroolsLogicalTuple> variableDeclaration,
                                                          Supplier<org.drools.model.PatternDSL.PatternDef<DroolsLogicalTuple>> patternBuilder)

    - #### ofInferred

          static <A> DroolsInferredMetadata<A> ofInferred(org.drools.model.Declaration<DroolsLogicalTuple> variableDeclaration,
                                                          Supplier<org.drools.model.PatternDSL.PatternDef<DroolsLogicalTuple>> patternBuilder,
                                                          int itemId)

    - #### ofGenuine

          static <A> DroolsGenuineMetadata<A> ofGenuine(org.drools.model.Declaration<A> 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

          org.drools.model.Declaration<LogicalFactType> getVariableDeclaration()

    - #### buildPattern

          org.drools.model.PatternDSL.PatternDef<LogicalFactType> 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<org.drools.model.PatternDSL.PatternDef<LogicalFactType>> 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.