From a155f6ba02e08a75ce6e474a86900b8363f506e8 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Wed, 29 Sep 2021 02:45:57 +0200 Subject: build: migration to Gradle 7 --- .../solver/data/query/view/RelationView.java | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/query/view/RelationView.java (limited to 'store/src/main/java/org/eclipse/viatra/solver/data/query/view/RelationView.java') diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/query/view/RelationView.java b/store/src/main/java/org/eclipse/viatra/solver/data/query/view/RelationView.java new file mode 100644 index 00000000..c5bc5228 --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/query/view/RelationView.java @@ -0,0 +1,85 @@ +package org.eclipse.viatra.solver.data.query.view; + +import java.util.Objects; + +import org.eclipse.viatra.query.runtime.matchers.context.common.BaseInputKeyWrapper; +import org.eclipse.viatra.solver.data.map.CursorAsIterator; +import org.eclipse.viatra.solver.data.model.Model; +import org.eclipse.viatra.solver.data.model.Tuple; +import org.eclipse.viatra.solver.data.model.representation.Relation; + +/** + * Represents a view of a {@link Relation} that can be queried. + * + * @author Oszkar Semerath + * + * @param + */ +public abstract class RelationView extends BaseInputKeyWrapper> { + protected final Relation representation; + + protected RelationView(Relation representation) { + super(null); + this.wrappedKey = this; + this.representation = representation; + } + + @Override + public String getPrettyPrintableName() { + return representation.getName(); + } + + @Override + public String getStringID() { + return representation.getName() + this.getClass().getName(); + } + + public Relation getRepresentation() { + return representation; + } + + @Override + public boolean isEnumerable() { + return true; + } + + protected abstract boolean filter(Tuple key, D value); + + protected abstract Object[] forwardMap(Tuple key, D value); + + public abstract boolean get(Model model, Object[] tuple); + + public Object[] transform(Tuple tuple, D value) { + if (filter(tuple, value)) { + return forwardMap(tuple, value); + } else + return null; + } + + public Iterable getAll(Model model) { + return (() -> new CursorAsIterator<>(model.getAll(representation), (k, v) -> forwardMap(k, v), + (k, v) -> filter(k, v))); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hash(representation); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (!(obj instanceof RelationView)) + return false; + @SuppressWarnings("unchecked") + RelationView other = ((RelationView) obj); + return Objects.equals(representation, other.representation); + } + +} -- cgit v1.2.3-70-g09d2