diff --git a/pom.xml b/pom.xml
index 6fe719e..9733dfb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -113,7 +113,7 @@
io.github.nergal-permjava-decita
- 0.5.1
+ 0.7.0-RCcom.renomad
diff --git a/src/main/java/ru/ewc/checklogic/Computation.java b/src/main/java/ru/ewc/checklogic/Computation.java
index 17ad395..47d0469 100644
--- a/src/main/java/ru/ewc/checklogic/Computation.java
+++ b/src/main/java/ru/ewc/checklogic/Computation.java
@@ -27,14 +27,7 @@
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import ru.ewc.commands.CommandsFacade;
import ru.ewc.decisions.api.ComputationContext;
-import ru.ewc.decisions.api.DecitaException;
-import ru.ewc.decisions.api.DecitaFacade;
-import ru.ewc.decisions.api.Locator;
-import ru.ewc.decisions.api.Locators;
/**
* I am a unique instance of a decision table computation.
@@ -44,35 +37,12 @@
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public final class Computation {
/**
- * Facade for making all the decisions.
+ * The context of the computation.
*/
- private final DecitaFacade decisions;
+ private final ComputationContext context;
- /**
- * Facade for executing all the commands.
- */
- private final CommandsFacade commands;
-
- /**
- * The current state of the system.
- */
- private final Locators state;
-
- /**
- * Ctor.
- *
- * @param decisions An instance of {@link DecitaFacade} to make decisions.
- * @param commands An instance of {@link CommandsFacade} to execute commands.
- * @param locators An instance of {@link Locators} to store the state.
- */
- public Computation(
- final DecitaFacade decisions,
- final CommandsFacade commands,
- final Locators locators
- ) {
- this.decisions = decisions;
- this.commands = commands;
- this.state = locators;
+ public Computation(final ComputationContext context) {
+ this.context = context;
}
/**
@@ -91,70 +61,19 @@ public static URI uriFrom(final String path) {
return URI.create(result.toString());
}
- /**
- * Computes the decision for a specified table.
- *
- * @param table Name of the tables to make a decision against.
- * @param locators The locators to use for the decision.
- * @return The collection of outcomes from the specified table.
- * @throws DecitaException If the table could not be found or computed.
- */
- public Map decideFor(final String table, final Locators locators)
- throws DecitaException {
- return this.decisions.decisionFor(table, this.state.mergedWith(locators));
- }
-
- public Map decideFor(final String table) throws DecitaException {
- return this.decisions.decisionFor(table, this.state);
- }
-
- public void perform(final Transition command) {
- this.commands.perform(command.name(), this.state.mergedWith(command.request()));
- }
-
- public boolean hasStateFor(final String table) {
- return this.state.hasLocator(table);
+ public void perform(final String command) {
+ this.context.perform(command);
}
public Map stateFor(final String table, final Map entities) {
- final Locator locator = this.state.locatorFor(table);
- final ComputationContext context = new ComputationContext(this.state);
final Map actual = HashMap.newHashMap(entities.size());
for (final String fragment : entities.keySet()) {
- actual.put(fragment, locator.fragmentBy(fragment, context));
+ actual.put(fragment, this.context.valueFor(table, fragment));
}
return actual;
}
- public Computation withState(final Map> incoming) {
- return new Computation(this.decisions, this.commands, stateFrom(incoming));
- }
-
public Map> storedState() {
- return this.state.state();
- }
-
- /**
- * Loads the state from the specified {@code InputStream}.
- *
- * @param stream InputStream containing state info.
- * @return Collection of {@link Locator} objects, containing desired state.
- */
- private static Locators stateFrom(final Map> stream) {
- return new Locators(
- stream
- .entrySet()
- .stream()
- .collect(Collectors.toMap(Map.Entry::getKey, entryToLocator()))
- );
- }
-
- /**
- * Converts a {@link Map.Entry} to a {@link Locator} object.
- *
- * @return A function that converts a {@link Map.Entry} to a {@link Locator} object.
- */
- private static Function>, Locator> entryToLocator() {
- return e -> new InMemoryStorage(e.getValue());
+ return this.context.state();
}
}
diff --git a/src/main/java/ru/ewc/checklogic/FileUtils.java b/src/main/java/ru/ewc/checklogic/FileUtils.java
new file mode 100644
index 0000000..0e7dfc6
--- /dev/null
+++ b/src/main/java/ru/ewc/checklogic/FileUtils.java
@@ -0,0 +1,127 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2024 Decision-Driven Development
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package ru.ewc.checklogic;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.stream.Stream;
+import lombok.SneakyThrows;
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ * I am a utility class that provides methods for file operations.
+ *
+ * @since 0.3.0
+ */
+public final class FileUtils {
+ /**
+ * Primary hidden constructor.
+ */
+ private FileUtils() {
+ // Utility class
+ }
+
+ static InputStream applicationConfig(final String root) throws IOException {
+ return Files.newInputStream(Path.of(root, "application.yaml"));
+ }
+
+ /**
+ * Gets the path to a folder with specified resources.
+ *
+ * @param resource Resource name to get its folder.
+ * @return Path to a resource folder as a String.
+ */
+ static String getFinalPathTo(final String resource) {
+ final String states;
+ if (System.getProperties().containsKey("sources")) {
+ states = String.format("%s/%s", System.getProperty("sources"), resource);
+ } else if (System.getProperties().containsKey(resource)) {
+ states = System.getProperty(resource);
+ } else {
+ states = String.format(
+ "%s%s%s",
+ System.getProperty("user.dir"),
+ "/src/test/resources/",
+ resource
+ );
+ }
+ return states;
+ }
+
+ @SneakyThrows
+ static Stream readFileNames() {
+ return Files.walk(Paths.get(Computation.uriFrom(getFinalPathTo("states"))))
+ .filter(Files::isRegularFile)
+ .map(
+ path -> path.toFile().getAbsolutePath()
+ ).map(
+ path -> {
+ final InputStream stream;
+ try {
+ stream = Files.newInputStream(Paths.get(path));
+ } catch (final IOException exception) {
+ throw new IllegalStateException(exception);
+ }
+ return FileUtils.createTestData(path, stream);
+ });
+ }
+
+ @SuppressWarnings("unchecked")
+ private static LogicChecker.TestData createTestData(
+ final String path,
+ final InputStream stream
+ ) {
+ final Iterator