Browse Source

Reworked Requirements (WIP)

jimFirstDesign
Felix Stupp 2 years ago
parent
commit
cddde8f42b
5 changed files with 126 additions and 17 deletions
  1. +78
    -0
      src/de/banananetwork/dsa/requirements/Requirement.java
  2. +0
    -6
      src/de/banananetwork/dsa/requirements/Requirement.kt
  3. +43
    -0
      src/de/banananetwork/dsa/requirements/RequirementCheckResult.java
  4. +5
    -0
      src/de/banananetwork/dsa/requirements/RequirementLink.java
  5. +0
    -11
      src/de/banananetwork/dsa/requirements/RequirementSet.java

+ 78
- 0
src/de/banananetwork/dsa/requirements/Requirement.java View File

@ -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<Supplier<Requirement>> requirements = new ArrayList<>();
private RequirementLink requirementLink;
public Builder(RequirementLink requirementLink) {
this.requirementLink = requirementLink;
}
Builder add(Supplier<Requirement> 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<Supplier<Requirement>> 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));
}
}
}
}

+ 0
- 6
src/de/banananetwork/dsa/requirements/Requirement.kt View File

@ -1,6 +0,0 @@
package de.banananetwork.dsa.requirements
class Requirement {
}

+ 43
- 0
src/de/banananetwork/dsa/requirements/RequirementCheckResult.java View File

@ -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;
}
}

+ 5
- 0
src/de/banananetwork/dsa/requirements/RequirementLink.java View File

@ -0,0 +1,5 @@
package de.banananetwork.dsa.requirements;
public enum RequirementLink {
AND, OR
}

+ 0
- 11
src/de/banananetwork/dsa/requirements/RequirementSet.java View File

@ -1,11 +0,0 @@
package de.banananetwork.dsa.requirements;
public class RequirementSet {
private final Requirement[] requirements;
public RequirementSet(Requirement[] requirements) {
this.requirements = requirements;
}
}

Loading…
Cancel
Save