All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.optaplanner.constraint.streams.bavet.bi.JoinBiNode Maven / Gradle / Ivy

Go to download

OptaPlanner solves planning problems. This lightweight, embeddable planning engine implements powerful and scalable algorithms to optimize business resource scheduling and planning. This module contains implementation of Constraint streams (Bavet).

There is a newer version: 10.0.0
Show newest version
package org.optaplanner.constraint.streams.bavet.bi;

import java.util.Map;
import java.util.function.Function;

import org.optaplanner.constraint.streams.bavet.common.AbstractJoinNode;
import org.optaplanner.constraint.streams.bavet.common.TupleLifecycle;
import org.optaplanner.constraint.streams.bavet.common.index.IndexProperties;
import org.optaplanner.constraint.streams.bavet.common.index.Indexer;
import org.optaplanner.constraint.streams.bavet.uni.UniTuple;

final class JoinBiNode extends AbstractJoinNode, B, BiTuple, BiTupleImpl> {

    private final Function mappingA;
    private final int outputStoreSize;

    public JoinBiNode(Function mappingA, Function mappingB,
            int inputStoreIndexA, int inputStoreIndexB,
            TupleLifecycle> nextNodesTupleLifecycle,
            int outputStoreSize,
            Indexer, Map, BiTupleImpl>> indexerA,
            Indexer, Map, BiTupleImpl>> indexerB) {
        super(mappingB, inputStoreIndexA, inputStoreIndexB, nextNodesTupleLifecycle, indexerA, indexerB);
        this.mappingA = mappingA;
        this.outputStoreSize = outputStoreSize;
    }

    @Override
    protected IndexProperties createIndexPropertiesLeft(UniTuple leftTuple) {
        return mappingA.apply(leftTuple.getFactA());
    }

    @Override
    protected BiTupleImpl createOutTuple(UniTuple leftTuple, UniTuple rightTuple) {
        return new BiTupleImpl<>(leftTuple.getFactA(), rightTuple.getFactA(), outputStoreSize);
    }

    @Override
    protected void updateOutTupleLeft(BiTupleImpl outTuple, UniTuple leftTuple) {
        outTuple.factA = leftTuple.getFactA();
    }

    @Override
    protected void updateOutTupleRight(BiTupleImpl outTuple, UniTuple rightTuple) {
        outTuple.factB = rightTuple.getFactA();
    }

    @Override
    public String toString() {
        return "JoinBiNode";
    }

}