org.optaplanner.constraint.streams.bavet.quad.BavetJoinQuadConstraintStream Maven / Gradle / Ivy
package org.optaplanner.constraint.streams.bavet.quad;
import java.util.Objects;
import java.util.Set;
import org.optaplanner.constraint.streams.bavet.BavetConstraintFactory;
import org.optaplanner.constraint.streams.bavet.common.AbstractJoinNode;
import org.optaplanner.constraint.streams.bavet.common.BavetAbstractConstraintStream;
import org.optaplanner.constraint.streams.bavet.common.BavetJoinConstraintStream;
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.tri.BavetJoinBridgeTriConstraintStream;
import org.optaplanner.constraint.streams.bavet.tri.TriTuple;
import org.optaplanner.constraint.streams.bavet.uni.BavetJoinBridgeUniConstraintStream;
import org.optaplanner.constraint.streams.common.quad.DefaultQuadJoiner;
import org.optaplanner.core.api.score.Score;
import org.optaplanner.core.api.score.stream.ConstraintStream;
public final class BavetJoinQuadConstraintStream
extends BavetAbstractQuadConstraintStream
implements BavetJoinConstraintStream {
private final BavetJoinBridgeTriConstraintStream leftParent;
private final BavetJoinBridgeUniConstraintStream rightParent;
private final DefaultQuadJoiner joiner;
public BavetJoinQuadConstraintStream(BavetConstraintFactory constraintFactory,
BavetJoinBridgeTriConstraintStream leftParent,
BavetJoinBridgeUniConstraintStream rightParent,
DefaultQuadJoiner joiner) {
super(constraintFactory, leftParent.getRetrievalSemantics());
this.leftParent = leftParent;
this.rightParent = rightParent;
this.joiner = joiner;
}
@Override
public boolean guaranteesDistinct() {
return leftParent.guaranteesDistinct() && rightParent.guaranteesDistinct();
}
// ************************************************************************
// Node creation
// ************************************************************************
@Override
public void collectActiveConstraintStreams(Set> constraintStreamSet) {
leftParent.collectActiveConstraintStreams(constraintStreamSet);
rightParent.collectActiveConstraintStreams(constraintStreamSet);
constraintStreamSet.add(this);
}
@Override
public ConstraintStream getTupleSource() {
return this;
}
@Override
public > void buildNode(NodeBuildHelper buildHelper) {
int inputStoreIndexAB = buildHelper.reserveTupleStoreIndex(leftParent.getTupleSource());
int inputStoreIndexC = buildHelper.reserveTupleStoreIndex(rightParent.getTupleSource());
int outputStoreSize = buildHelper.extractTupleStoreSize(this);
IndexerFactory indexerFactory = new IndexerFactory(joiner);
AbstractJoinNode, D, QuadTuple, QuadTupleImpl> node = new JoinQuadNode<>(
JoinerUtils.combineLeftMappings(joiner), JoinerUtils.combineRightMappings(joiner),
inputStoreIndexAB, inputStoreIndexC,
buildHelper.getAggregatedTupleLifecycle(childStreamList),
outputStoreSize, indexerFactory.buildIndexer(true), indexerFactory.buildIndexer(false));
buildHelper.addNode(node, leftParent, rightParent);
}
// ************************************************************************
// Equality for node sharing
// ************************************************************************
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BavetJoinQuadConstraintStream, ?, ?, ?, ?> other = (BavetJoinQuadConstraintStream, ?, ?, ?, ?>) o;
/*
* Bridge streams do not implement equality because their equals() would have to point back to this stream,
* resulting in StackOverflowError.
* Therefore we need to check bridge parents to see where this join node comes from.
*/
return Objects.equals(leftParent.getParent(), other.leftParent.getParent())
&& Objects.equals(rightParent.getParent(), other.rightParent.getParent())
&& Objects.equals(joiner, other.joiner);
}
@Override
public int hashCode() {
return Objects.hash(leftParent.getParent(), rightParent.getParent(), joiner);
}
@Override
public String toString() {
return "QuadJoin() with " + childStreamList.size() + " children";
}
// ************************************************************************
// Getters/setters
// ************************************************************************
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy