From cddde8f42b4d32b645707ee05c13907cf667a29e Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Sun, 15 Jul 2018 20:35:14 +0200 Subject: [PATCH] Reworked Requirements (WIP) --- .../dsa/requirements/Requirement.java | 78 +++++++++++++++++++ .../dsa/requirements/Requirement.kt | 6 -- .../requirements/RequirementCheckResult.java | 43 ++++++++++ .../dsa/requirements/RequirementLink.java | 5 ++ .../dsa/requirements/RequirementSet.java | 11 --- 5 files changed, 126 insertions(+), 17 deletions(-) create mode 100644 src/de/banananetwork/dsa/requirements/Requirement.java delete mode 100644 src/de/banananetwork/dsa/requirements/Requirement.kt create mode 100644 src/de/banananetwork/dsa/requirements/RequirementCheckResult.java create mode 100644 src/de/banananetwork/dsa/requirements/RequirementLink.java delete mode 100644 src/de/banananetwork/dsa/requirements/RequirementSet.java diff --git a/src/de/banananetwork/dsa/requirements/Requirement.java b/src/de/banananetwork/dsa/requirements/Requirement.java new file mode 100644 index 0000000..ee43ce0 --- /dev/null +++ b/src/de/banananetwork/dsa/requirements/Requirement.java @@ -0,0 +1,78 @@ +package de.banananetwork.dsa.requirements; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.function.Supplier; + +public abstract class Requirement { + + public abstract RequirementCheckResult checkOn(Character character); + + private static class SingleRequirement extends Requirement { + + + } + + private static class CombinedRequirement extends Requirement { + + private final RequirementLink requirementLink; + private final Requirement[] requirements; + + private CombinedRequirement(RequirementLink requirementLink, Requirement[] requirements) { + this.requirementLink = requirementLink; + this.requirements = requirements; + } + + @Override + public RequirementCheckResult checkOn(Character character) { + return null; + } + + } + + public static class Builder { + + private final List> requirements = new ArrayList<>(); + private RequirementLink requirementLink; + + public Builder(RequirementLink requirementLink) { + this.requirementLink = requirementLink; + } + + Builder add(Supplier requirementSupplier) { + this.requirements.add(requirementSupplier); + return this; + } + + public Builder add(Requirement requirement) { + return this.add(() -> requirement); + } + + public Builder add(Builder requirement) { + return this.add(requirement::create); + } + + private Builder addAll(Collection> requirements) { + this.requirements.addAll(requirements); + return this; + } + + public Builder addAll(Builder requirements) { + return this.addAll(requirements.requirements); + } + + private Requirement create() { + switch (this.requirements.size()) { + case 0: + throw new IllegalStateException(); + case 1: + return this.requirements.get(0).get(); + default: + return new CombinedRequirement(this.requirementLink, this.requirements.stream().map(Supplier::get).toArray(Requirement[]::new)); + } + } + + } + +} diff --git a/src/de/banananetwork/dsa/requirements/Requirement.kt b/src/de/banananetwork/dsa/requirements/Requirement.kt deleted file mode 100644 index 9e7715a..0000000 --- a/src/de/banananetwork/dsa/requirements/Requirement.kt +++ /dev/null @@ -1,6 +0,0 @@ -package de.banananetwork.dsa.requirements - -class Requirement { - - -} \ No newline at end of file diff --git a/src/de/banananetwork/dsa/requirements/RequirementCheckResult.java b/src/de/banananetwork/dsa/requirements/RequirementCheckResult.java new file mode 100644 index 0000000..e15b9ef --- /dev/null +++ b/src/de/banananetwork/dsa/requirements/RequirementCheckResult.java @@ -0,0 +1,43 @@ +package de.banananetwork.dsa.requirements; + +public abstract class RequirementCheckResult { + + private final Requirement requirement; + + private RequirementCheckResult(Requirement requirement) { + this.requirement = requirement; + } + + public Requirement getRequirement() { + return requirement; + } + + public enum State { + + ACCEPTED(0), WARNING(1), ERROR(2); + + private final int priority; + + State(int priority) { + this.priority = priority; + } + + public State combine(State state) { + return state.priority > this.priority ? state : this; + } + + } + + private static class SingleResult extends RequirementCheckResult { + + + } + + private static class CombinedResult extends RequirementCheckResult { + + RequirementCheckResult[] results; + + + } + +} diff --git a/src/de/banananetwork/dsa/requirements/RequirementLink.java b/src/de/banananetwork/dsa/requirements/RequirementLink.java new file mode 100644 index 0000000..79a89b9 --- /dev/null +++ b/src/de/banananetwork/dsa/requirements/RequirementLink.java @@ -0,0 +1,5 @@ +package de.banananetwork.dsa.requirements; + +public enum RequirementLink { + AND, OR +} diff --git a/src/de/banananetwork/dsa/requirements/RequirementSet.java b/src/de/banananetwork/dsa/requirements/RequirementSet.java deleted file mode 100644 index 3467573..0000000 --- a/src/de/banananetwork/dsa/requirements/RequirementSet.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.banananetwork.dsa.requirements; - -public class RequirementSet { - - private final Requirement[] requirements; - - public RequirementSet(Requirement[] requirements) { - this.requirements = requirements; - } - -} \ No newline at end of file