aboutsummaryrefslogtreecommitdiffstats
path: root/store/src/main/java/org/eclipse/viatra/solver/data/query/view/RelationView.java
diff options
context:
space:
mode:
Diffstat (limited to 'store/src/main/java/org/eclipse/viatra/solver/data/query/view/RelationView.java')
-rw-r--r--store/src/main/java/org/eclipse/viatra/solver/data/query/view/RelationView.java85
1 files changed, 0 insertions, 85 deletions
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
deleted file mode 100644
index c5bc5228..00000000
--- a/store/src/main/java/org/eclipse/viatra/solver/data/query/view/RelationView.java
+++ /dev/null
@@ -1,85 +0,0 @@
1package org.eclipse.viatra.solver.data.query.view;
2
3import java.util.Objects;
4
5import org.eclipse.viatra.query.runtime.matchers.context.common.BaseInputKeyWrapper;
6import org.eclipse.viatra.solver.data.map.CursorAsIterator;
7import org.eclipse.viatra.solver.data.model.Model;
8import org.eclipse.viatra.solver.data.model.Tuple;
9import org.eclipse.viatra.solver.data.model.representation.Relation;
10
11/**
12 * Represents a view of a {@link Relation} that can be queried.
13 *
14 * @author Oszkar Semerath
15 *
16 * @param <D>
17 */
18public abstract class RelationView<D> extends BaseInputKeyWrapper<RelationView<D>> {
19 protected final Relation<D> representation;
20
21 protected RelationView(Relation<D> representation) {
22 super(null);
23 this.wrappedKey = this;
24 this.representation = representation;
25 }
26
27 @Override
28 public String getPrettyPrintableName() {
29 return representation.getName();
30 }
31
32 @Override
33 public String getStringID() {
34 return representation.getName() + this.getClass().getName();
35 }
36
37 public Relation<D> getRepresentation() {
38 return representation;
39 }
40
41 @Override
42 public boolean isEnumerable() {
43 return true;
44 }
45
46 protected abstract boolean filter(Tuple key, D value);
47
48 protected abstract Object[] forwardMap(Tuple key, D value);
49
50 public abstract boolean get(Model model, Object[] tuple);
51
52 public Object[] transform(Tuple tuple, D value) {
53 if (filter(tuple, value)) {
54 return forwardMap(tuple, value);
55 } else
56 return null;
57 }
58
59 public Iterable<Object[]> getAll(Model model) {
60 return (() -> new CursorAsIterator<>(model.getAll(representation), (k, v) -> forwardMap(k, v),
61 (k, v) -> filter(k, v)));
62 }
63
64 @Override
65 public int hashCode() {
66 final int prime = 31;
67 int result = 1;
68 result = prime * result + Objects.hash(representation);
69 return result;
70 }
71
72 @Override
73 public boolean equals(Object obj) {
74 if (this == obj)
75 return true;
76 if (!super.equals(obj))
77 return false;
78 if (!(obj instanceof RelationView))
79 return false;
80 @SuppressWarnings("unchecked")
81 RelationView<D> other = ((RelationView<D>) obj);
82 return Objects.equals(representation, other.representation);
83 }
84
85}