diff options
Diffstat (limited to 'store/src/main/java/org/eclipse/viatra/solver/data/query/view')
4 files changed, 0 insertions, 199 deletions
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/query/view/FilteredRelationView.java b/store/src/main/java/org/eclipse/viatra/solver/data/query/view/FilteredRelationView.java deleted file mode 100644 index edc534b7..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/query/view/FilteredRelationView.java +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.query.view; | ||
2 | |||
3 | import java.util.function.BiPredicate; | ||
4 | |||
5 | import org.eclipse.viatra.solver.data.model.Model; | ||
6 | import org.eclipse.viatra.solver.data.model.Tuple; | ||
7 | import org.eclipse.viatra.solver.data.model.Tuple.Tuple1; | ||
8 | import org.eclipse.viatra.solver.data.model.representation.Relation; | ||
9 | |||
10 | public class FilteredRelationView<D> extends RelationView<D>{ | ||
11 | private final BiPredicate<Tuple,D> predicate; | ||
12 | |||
13 | public FilteredRelationView(Relation<D> representation, BiPredicate<Tuple,D> predicate) { | ||
14 | super(representation); | ||
15 | this.predicate = predicate; | ||
16 | } | ||
17 | @Override | ||
18 | protected Object[] forwardMap(Tuple key, D value) { | ||
19 | return toTuple1Array(key); | ||
20 | } | ||
21 | @Override | ||
22 | public boolean get(Model model, Object[] tuple) { | ||
23 | int[] content = new int[tuple.length]; | ||
24 | for(int i = 0; i<tuple.length; i++) { | ||
25 | content[i] =((Tuple1)tuple[i]).get(0); | ||
26 | } | ||
27 | Tuple key = Tuple.of(content); | ||
28 | D value = model.get(representation, key); | ||
29 | return filter(key, value); | ||
30 | } | ||
31 | |||
32 | public static Object[] toTuple1Array(Tuple t) { | ||
33 | Object[] result = new Object[t.getSize()]; | ||
34 | for(int i = 0; i<t.getSize(); i++) { | ||
35 | result[i] = t.get(i); | ||
36 | } | ||
37 | return result; | ||
38 | } | ||
39 | |||
40 | @Override | ||
41 | public int getArity() { | ||
42 | return this.representation.getArity(); | ||
43 | } | ||
44 | @Override | ||
45 | protected boolean filter(Tuple key, D value) { | ||
46 | return this.predicate.test(key, value); | ||
47 | } | ||
48 | } | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/query/view/FunctionalRelationView.java b/store/src/main/java/org/eclipse/viatra/solver/data/query/view/FunctionalRelationView.java deleted file mode 100644 index 4aa7cfd0..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/query/view/FunctionalRelationView.java +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.query.view; | ||
2 | |||
3 | import org.eclipse.viatra.solver.data.model.Model; | ||
4 | import org.eclipse.viatra.solver.data.model.Tuple; | ||
5 | import org.eclipse.viatra.solver.data.model.Tuple.Tuple1; | ||
6 | import org.eclipse.viatra.solver.data.model.representation.Relation; | ||
7 | |||
8 | public class FunctionalRelationView<D> extends RelationView<D> { | ||
9 | |||
10 | public FunctionalRelationView(Relation<D> representation) { | ||
11 | super(representation); | ||
12 | } | ||
13 | |||
14 | @Override | ||
15 | protected boolean filter(Tuple key, D value) { | ||
16 | return true; | ||
17 | } | ||
18 | |||
19 | @Override | ||
20 | protected Object[] forwardMap(Tuple key, D value) { | ||
21 | return toTuple1ArrayPlusValue(key, value); | ||
22 | } | ||
23 | |||
24 | @Override | ||
25 | public boolean get(Model model, Object[] tuple) { | ||
26 | int[] content = new int[tuple.length-1]; | ||
27 | for(int i = 0; i<tuple.length-1; i++) { | ||
28 | content[i] =((Tuple1)tuple[i]).get(0); | ||
29 | } | ||
30 | Tuple key = Tuple.of(content); | ||
31 | @SuppressWarnings("unchecked") | ||
32 | D valueInTuple = (D) tuple[tuple.length-1]; | ||
33 | D valueInMap = model.get(representation, key); | ||
34 | return valueInTuple.equals(valueInMap); | ||
35 | } | ||
36 | |||
37 | public static <D> Object[] toTuple1ArrayPlusValue(Tuple t, D value) { | ||
38 | Object[] result = new Object[t.getSize()+1]; | ||
39 | for(int i = 0; i<t.getSize(); i++) { | ||
40 | result[i] = t.get(i); | ||
41 | } | ||
42 | result[t.getSize()] = value; | ||
43 | return result; | ||
44 | } | ||
45 | |||
46 | @Override | ||
47 | public int getArity() { | ||
48 | return this.representation.getArity()+1; | ||
49 | } | ||
50 | } | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/query/view/KeyOnlyRelationView.java b/store/src/main/java/org/eclipse/viatra/solver/data/query/view/KeyOnlyRelationView.java deleted file mode 100644 index 11a24fc8..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/query/view/KeyOnlyRelationView.java +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.query.view; | ||
2 | |||
3 | import org.eclipse.viatra.solver.data.model.Tuple; | ||
4 | import org.eclipse.viatra.solver.data.model.representation.Relation; | ||
5 | |||
6 | public class KeyOnlyRelationView extends FilteredRelationView<Boolean>{ | ||
7 | |||
8 | public KeyOnlyRelationView(Relation<Boolean> representation) { | ||
9 | super(representation, (k,v)->true); | ||
10 | } | ||
11 | @Override | ||
12 | protected boolean filter(Tuple key, Boolean value) { | ||
13 | return true; | ||
14 | } | ||
15 | |||
16 | } | ||
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 @@ | |||
1 | package org.eclipse.viatra.solver.data.query.view; | ||
2 | |||
3 | import java.util.Objects; | ||
4 | |||
5 | import org.eclipse.viatra.query.runtime.matchers.context.common.BaseInputKeyWrapper; | ||
6 | import org.eclipse.viatra.solver.data.map.CursorAsIterator; | ||
7 | import org.eclipse.viatra.solver.data.model.Model; | ||
8 | import org.eclipse.viatra.solver.data.model.Tuple; | ||
9 | import 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 | */ | ||
18 | public 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 | } | ||