blob: 4602af21df705c42e7ada63875a5b82d5464dce0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package org.eclipse.viatra.solver.data.query.view;
import java.util.function.BiPredicate;
import org.eclipse.viatra.solver.data.model.Model;
import org.eclipse.viatra.solver.data.model.Tuple;
import org.eclipse.viatra.solver.data.model.Tuple.Tuple1;
import org.eclipse.viatra.solver.data.model.representation.Relation;
public class FilteredRelationView<D> extends RelationView<D>{
private final BiPredicate<Tuple,D> predicate;
public FilteredRelationView(Model model, Relation<D> representation, BiPredicate<Tuple,D> predicate) {
super(model, representation);
this.predicate = predicate;
}
@Override
protected Object[] forwardMap(Tuple key, D value) {
return toTuple1Array(key);
}
@Override
public boolean get(Object[] tuple) {
int[] content = new int[tuple.length];
for(int i = 0; i<tuple.length; i++) {
content[i] =((Tuple1)tuple[i]).get(0);
}
Tuple key = Tuple.of(content);
D value = this.model.get(representation, key);
return filter(key, value);
}
public static Object[] toTuple1Array(Tuple t) {
Object[] result = new Object[t.getSize()];
for(int i = 0; i<t.getSize(); i++) {
result[i] = t.get(i);
}
return result;
}
@Override
public int getArity() {
return this.representation.getArity();
}
@Override
protected boolean filter(Tuple key, D value) {
return this.predicate.test(key, value);
}
}
|