diff options
author | 2021-09-29 02:45:57 +0200 | |
---|---|---|
committer | 2021-09-29 03:16:01 +0200 | |
commit | a155f6ba02e08a75ce6e474a86900b8363f506e8 (patch) | |
tree | b78804c1c0f0968a9625f0656e08f5dadc16924c /store/src/main/java/org/eclipse/viatra/solver/data/query/building/PredicateBuilder_string.java | |
parent | Simplify branding (diff) | |
download | refinery-a155f6ba02e08a75ce6e474a86900b8363f506e8.tar.gz refinery-a155f6ba02e08a75ce6e474a86900b8363f506e8.tar.zst refinery-a155f6ba02e08a75ce6e474a86900b8363f506e8.zip |
build: migration to Gradle 7
Diffstat (limited to 'store/src/main/java/org/eclipse/viatra/solver/data/query/building/PredicateBuilder_string.java')
-rw-r--r-- | store/src/main/java/org/eclipse/viatra/solver/data/query/building/PredicateBuilder_string.java | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/query/building/PredicateBuilder_string.java b/store/src/main/java/org/eclipse/viatra/solver/data/query/building/PredicateBuilder_string.java new file mode 100644 index 00000000..41f85d39 --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/query/building/PredicateBuilder_string.java | |||
@@ -0,0 +1,107 @@ | |||
1 | package org.eclipse.viatra.solver.data.query.building; | ||
2 | |||
3 | import java.util.ArrayList; | ||
4 | import java.util.Collections; | ||
5 | import java.util.HashSet; | ||
6 | import java.util.List; | ||
7 | |||
8 | import org.eclipse.viatra.solver.data.query.view.RelationView; | ||
9 | |||
10 | public class PredicateBuilder_string { | ||
11 | private PredicateBuilder_string() {} | ||
12 | |||
13 | public static PredicateBuild1 predicate(String name) { | ||
14 | return new PredicateBuild1(name); | ||
15 | } | ||
16 | public static class PredicateBuild1 { | ||
17 | private String name; | ||
18 | public PredicateBuild1(String name) { | ||
19 | this.name = name; | ||
20 | } | ||
21 | public PredicateBuild2 parameters(String... parameters) { | ||
22 | return new PredicateBuild2(name, parameters); | ||
23 | } | ||
24 | } | ||
25 | public static class PredicateBuild2 { | ||
26 | private String name; | ||
27 | private String[] parameters; | ||
28 | public PredicateBuild2(String name, String[] parameters) { | ||
29 | this.name = name; | ||
30 | this.parameters = parameters; | ||
31 | } | ||
32 | |||
33 | public PredicateBuild3 clause(DNFAtom...constraints) { | ||
34 | return new PredicateBuild3(name,parameters,List.<DNFAtom[]>of(constraints)); | ||
35 | } | ||
36 | } | ||
37 | public static class PredicateBuild3 { | ||
38 | String name; | ||
39 | String[] parameters; | ||
40 | List<DNFAtom[]> clauses; | ||
41 | public PredicateBuild3(String name, String[] parameters, List<DNFAtom[]> clauses) { | ||
42 | super(); | ||
43 | this.name = name; | ||
44 | this.parameters = parameters; | ||
45 | this.clauses = clauses; | ||
46 | } | ||
47 | |||
48 | public PredicateBuild3 clause(DNFAtom...constraints) { | ||
49 | List<DNFAtom[]> newClauses = new ArrayList<>(); | ||
50 | newClauses.addAll(clauses); | ||
51 | newClauses.add(constraints); | ||
52 | return new PredicateBuild3(name, parameters, newClauses); | ||
53 | } | ||
54 | public DNFPredicate build() { | ||
55 | List<Variable> newParameters = new ArrayList<>(this.parameters.length); | ||
56 | for(int i = 0; i<this.parameters.length; i++) { | ||
57 | newParameters.add(new Variable(parameters[i])); | ||
58 | } | ||
59 | |||
60 | List<DNFAnd> newClauses = new ArrayList<>(this.clauses.size()); | ||
61 | for(DNFAtom[] clause : this.clauses) { | ||
62 | List<DNFAtom> constraints = new ArrayList<>(clause.length); | ||
63 | Collections.addAll(constraints, clause); | ||
64 | newClauses.add(new DNFAnd(new HashSet<>(), constraints)); | ||
65 | } | ||
66 | |||
67 | return new DNFPredicate(name,newParameters,newClauses); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | private static Variable stringToVariable(String name) { | ||
72 | if(name != null) { | ||
73 | return new Variable(name); | ||
74 | } else { | ||
75 | return null; | ||
76 | } | ||
77 | } | ||
78 | private static List<Variable> stringToVariable(String[] names) { | ||
79 | List<Variable> variables = new ArrayList<>(); | ||
80 | for(int i = 0; i<names.length; i++) { | ||
81 | variables.add(stringToVariable(names[i])); | ||
82 | } | ||
83 | return variables; | ||
84 | } | ||
85 | |||
86 | public static EquivalenceAtom cEquals(String v1, String v2) { | ||
87 | return new EquivalenceAtom(true,stringToVariable(v1),stringToVariable(v2)); | ||
88 | } | ||
89 | public static EquivalenceAtom cNotEquals(String v1, String v2) { | ||
90 | return new EquivalenceAtom(false,stringToVariable(v1),stringToVariable(v2)); | ||
91 | } | ||
92 | |||
93 | public static RelationAtom cInRelation(RelationView<?> view, String... variables) { | ||
94 | |||
95 | return new RelationAtom(view, stringToVariable(variables)); | ||
96 | } | ||
97 | |||
98 | public static PredicateAtom cInPredicate(DNFPredicate referred, String... variables) { | ||
99 | return new PredicateAtom(true, false, referred, stringToVariable(variables)); | ||
100 | } | ||
101 | public static PredicateAtom cInTransitivePredicate(DNFPredicate referred, String... variables) { | ||
102 | return new PredicateAtom(true, true, referred, stringToVariable(variables)); | ||
103 | } | ||
104 | public static PredicateAtom cNotInPredicate(DNFPredicate referred, String... variables) { | ||
105 | return new PredicateAtom(false, false, referred, stringToVariable(variables)); | ||
106 | } | ||
107 | } | ||