diff options
Diffstat (limited to 'subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/TransformationRule.java')
-rw-r--r-- | subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/TransformationRule.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/TransformationRule.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/TransformationRule.java new file mode 100644 index 00000000..d64a3db1 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/TransformationRule.java | |||
@@ -0,0 +1,63 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.dse.transition; | ||
7 | |||
8 | import tools.refinery.store.model.Model; | ||
9 | import tools.refinery.store.model.ModelStoreBuilder; | ||
10 | import tools.refinery.store.query.ModelQueryAdapter; | ||
11 | import tools.refinery.store.query.ModelQueryBuilder; | ||
12 | import tools.refinery.store.query.dnf.RelationalQuery; | ||
13 | import tools.refinery.store.dse.ActionFactory; | ||
14 | import tools.refinery.store.query.resultset.OrderedResultSet; | ||
15 | import tools.refinery.store.query.resultset.ResultSet; | ||
16 | import tools.refinery.store.tuple.Tuple; | ||
17 | |||
18 | import java.util.*; | ||
19 | |||
20 | public class TransformationRule { | ||
21 | |||
22 | private final String name; | ||
23 | private final RelationalQuery precondition; | ||
24 | private final ActionFactory actionFactory; | ||
25 | |||
26 | private Random random; | ||
27 | private ModelQueryAdapter queryEngine; | ||
28 | |||
29 | public TransformationRule(String name, RelationalQuery precondition, ActionFactory actionFactory) { | ||
30 | this(name, precondition, actionFactory, new Random()); | ||
31 | } | ||
32 | |||
33 | public TransformationRule(String name, RelationalQuery precondition, ActionFactory actionFactory, long seed) { | ||
34 | this(name, precondition, actionFactory, new Random(seed)); | ||
35 | } | ||
36 | |||
37 | public TransformationRule(String name, RelationalQuery precondition, ActionFactory actionFactory, Random random) { | ||
38 | this.name = name; | ||
39 | this.precondition = precondition; | ||
40 | this.actionFactory = actionFactory; | ||
41 | this.random = random; | ||
42 | } | ||
43 | public void doConfigure(ModelStoreBuilder storeBuilder) { | ||
44 | var queryBuilder = storeBuilder.getAdapter(ModelQueryBuilder.class); | ||
45 | queryBuilder.query(this.precondition); | ||
46 | } | ||
47 | |||
48 | public Transformation prepare(Model model) { | ||
49 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
50 | var activations = new OrderedResultSet<>(queryEngine.getResultSet(precondition)); | ||
51 | var action = actionFactory.prepare(model); | ||
52 | return new Transformation(this,activations,action); | ||
53 | } | ||
54 | |||
55 | public String getName() { | ||
56 | return name; | ||
57 | } | ||
58 | |||
59 | public RelationalQuery getPrecondition() { | ||
60 | return precondition; | ||
61 | } | ||
62 | |||
63 | } | ||