Reworked Requirements (WIP)
parent
3bf0b0c5f9
commit
cddde8f42b
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +0,0 @@
|
|||||||
package de.banananetwork.dsa.requirements
|
|
||||||
|
|
||||||
class Requirement {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package de.banananetwork.dsa.requirements;
|
||||||
|
|
||||||
|
public enum RequirementLink {
|
||||||
|
AND, OR
|
||||||
|
}
|
@ -1,11 +0,0 @@
|
|||||||
package de.banananetwork.dsa.requirements;
|
|
||||||
|
|
||||||
public class RequirementSet {
|
|
||||||
|
|
||||||
private final Requirement[] requirements;
|
|
||||||
|
|
||||||
public RequirementSet(Requirement[] requirements) {
|
|
||||||
this.requirements = requirements;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue