org.optaplanner.constraint.streams.bavet.bi.BavetIfExistsBiConstraintStream Maven / Gradle / Ivy
package org.optaplanner.constraint.streams.bavet.bi;
import java.util.Set;
import org.optaplanner.constraint.streams.bavet.BavetConstraintFactory;
import org.optaplanner.constraint.streams.bavet.common.AbstractIfExistsNode;
import org.optaplanner.constraint.streams.bavet.common.BavetAbstractConstraintStream;
import org.optaplanner.constraint.streams.bavet.common.NodeBuildHelper;
import org.optaplanner.constraint.streams.bavet.common.index.IndexerFactory;
import org.optaplanner.constraint.streams.bavet.common.index.JoinerUtils;
import org.optaplanner.constraint.streams.bavet.uni.BavetIfExistsBridgeUniConstraintStream;
import org.optaplanner.constraint.streams.common.tri.DefaultTriJoiner;
import org.optaplanner.core.api.function.TriPredicate;
import org.optaplanner.core.api.score.Score;
import org.optaplanner.core.api.score.stream.ConstraintStream;
public final class BavetIfExistsBiConstraintStream
extends BavetAbstractBiConstraintStream {
private final BavetAbstractBiConstraintStream parentAB;
private final BavetIfExistsBridgeUniConstraintStream parentBridgeC;
private final boolean shouldExist;
private final DefaultTriJoiner joiner;
private final TriPredicate filtering;
public BavetIfExistsBiConstraintStream(BavetConstraintFactory constraintFactory,
BavetAbstractBiConstraintStream parentAB,
BavetIfExistsBridgeUniConstraintStream parentBridgeC,
boolean shouldExist,
DefaultTriJoiner joiner, TriPredicate filtering) {
super(constraintFactory, parentAB.getRetrievalSemantics());
this.parentAB = parentAB;
this.parentBridgeC = parentBridgeC;
this.shouldExist = shouldExist;
this.joiner = joiner;
this.filtering = filtering;
}
@Override
public boolean guaranteesDistinct() {
return parentAB.guaranteesDistinct();
}
// ************************************************************************
// Node creation
// ************************************************************************
@Override
public void collectActiveConstraintStreams(Set> constraintStreamSet) {
parentAB.collectActiveConstraintStreams(constraintStreamSet);
parentBridgeC.collectActiveConstraintStreams(constraintStreamSet);
constraintStreamSet.add(this);
}
@Override
public ConstraintStream getTupleSource() {
return parentAB.getTupleSource();
}
@Override
public > void buildNode(NodeBuildHelper buildHelper) {
int inputStoreIndexA = buildHelper.reserveTupleStoreIndex(parentAB.getTupleSource());
int inputStoreIndexB = buildHelper.reserveTupleStoreIndex(parentBridgeC.getTupleSource());
IndexerFactory indexerFactory = new IndexerFactory(joiner);
AbstractIfExistsNode, C> node = new IfExistsBiWithUniNode<>(shouldExist,
JoinerUtils.combineLeftMappings(joiner), JoinerUtils.combineRightMappings(joiner),
inputStoreIndexA, inputStoreIndexB,
buildHelper.getAggregatedTupleLifecycle(childStreamList),
indexerFactory.buildIndexer(true), indexerFactory.buildIndexer(false),
filtering);
buildHelper.addNode(node, this, parentBridgeC);
}
// ************************************************************************
// Equality for node sharing
// ************************************************************************
// TODO
@Override
public String toString() {
return "IfExists() with " + childStreamList.size() + " children";
}
// ************************************************************************
// Getters/setters
// ************************************************************************
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy