/* * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors * * SPDX-License-Identifier: EPL-2.0 */ package tools.refinery.store.query; import tools.refinery.store.query.equality.LiteralEqualityHelper; import tools.refinery.store.query.literal.*; import tools.refinery.store.query.term.*; import java.util.List; public interface Constraint { String name(); List getParameters(); default int arity() { return getParameters().size(); } default boolean invalidIndex(int i) { return i < 0 || i >= arity(); } default Reduction getReduction() { return Reduction.NOT_REDUCIBLE; } default boolean equals(LiteralEqualityHelper helper, Constraint other) { return equals(other); } default String toReferenceString() { return name(); } default CallLiteral call(CallPolarity polarity, List arguments) { return new CallLiteral(polarity, this, arguments); } default CallLiteral call(CallPolarity polarity, Variable... arguments) { return call(polarity, List.of(arguments)); } default CallLiteral call(Variable... arguments) { return call(CallPolarity.POSITIVE, arguments); } default CallLiteral callTransitive(NodeVariable left, NodeVariable right) { return call(CallPolarity.TRANSITIVE, List.of(left, right)); } default AssignedValue count(List arguments) { return targetVariable -> new CountLiteral(targetVariable, this, arguments); } default AssignedValue count(Variable... arguments) { return count(List.of(arguments)); } default AssignedValue aggregateBy(DataVariable inputVariable, Aggregator aggregator, List arguments) { return targetVariable -> new AggregationLiteral<>(targetVariable, aggregator, inputVariable, this, arguments); } default AssignedValue aggregateBy(DataVariable inputVariable, Aggregator aggregator, Variable... arguments) { return aggregateBy(inputVariable, aggregator, List.of(arguments)); } }