public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder {
- private ControlLoopGuard CLGuard;
+ private ControlLoopGuard cLGuard;
public ControlLoopGuardBuilderImpl(Guard guard) {
- CLGuard = new ControlLoopGuard();
- CLGuard.guard = guard;
+ cLGuard = new ControlLoopGuard();
+ cLGuard.setGuard(guard);
}
@Override
if (!policy.isValid()) {
throw new BuilderException("Invalid guard policy - some required fields are missing");
}
- if (CLGuard.guards == null) {
- CLGuard.guards = new LinkedList<GuardPolicy>();
+ if (cLGuard.getGuards() == null) {
+ cLGuard.setGuards(new LinkedList<>());
}
- CLGuard.guards.add(policy);
+ cLGuard.getGuards().add(policy);
}
return this;
}
if (policies == null) {
throw new BuilderException("GuardPolicy must not be null");
}
- if (CLGuard.guards == null) {
+ if (cLGuard.getGuards() == null) {
throw new BuilderException("No existing guard policies to remove");
}
for (GuardPolicy policy : policies) {
if (!policy.isValid()) {
throw new BuilderException("Invalid guard policy - some required fields are missing");
}
- boolean removed = CLGuard.guards.remove(policy);
+ boolean removed = cLGuard.getGuards().remove(policy);
if (!removed) {
- throw new BuilderException("Unknown guard policy: " + policy.name);
+ throw new BuilderException("Unknown guard policy: " + policy.getName());
}
}
return this;
@Override
public ControlLoopGuardBuilder removeAllGuardPolicies() throws BuilderException {
- CLGuard.guards.clear();
+ cLGuard.getGuards().clear();
return this;
}
if (constraints == null) {
throw new BuilderException("Constraint much not be null");
}
+ if (!addLimitConstraints(id,constraints)) {
+ throw new BuilderException("No existing guard policy matching the id: " + id);
+ }
+ return this;
+ }
+
+ private boolean addLimitConstraints(String id, Constraint... constraints) throws BuilderException {
boolean exist = false;
- for (GuardPolicy policy: CLGuard.guards) {
+ for (GuardPolicy policy: cLGuard.getGuards()) {
//
// We could have only one guard policy matching the id
//
- if (policy.id.equals(id)) {
+ if (policy.getId().equals(id)) {
exist = true;
for (Constraint cons: constraints) {
if (!cons.isValid()) {
throw new BuilderException("Invalid guard constraint - some required fields are missing");
}
- if (policy.limit_constraints == null) {
- policy.limit_constraints = new LinkedList<Constraint>();
+ if (policy.getLimit_constraints() == null) {
+ policy.setLimit_constraints(new LinkedList<>());
}
- policy.limit_constraints.add(cons);
+ policy.getLimit_constraints().add(cons);
}
break;
}
}
- if (exist == false) {
- throw new BuilderException("No existing guard policy matching the id: " + id);
- }
- return this;
+ return exist;
}
@Override
if (constraints == null) {
throw new BuilderException("Constraint much not be null");
}
+ if (!removeConstraints(id, constraints)) {
+ throw new BuilderException("No existing guard policy matching the id: " + id);
+ }
+ return this;
+ }
+
+ private boolean removeConstraints(String id, Constraint... constraints) throws BuilderException {
boolean exist = false;
- for (GuardPolicy policy: CLGuard.guards) {
+ for (GuardPolicy policy: cLGuard.getGuards()) {
//
// We could have only one guard policy matching the id
//
- if (policy.id.equals(id)) {
+ if (policy.getId().equals(id)) {
exist = true;
for (Constraint cons: constraints) {
if (!cons.isValid()) {
throw new BuilderException("Invalid guard constraint - some required fields are missing");
}
- boolean removed = policy.limit_constraints.remove(cons);
+ boolean removed = policy.getLimit_constraints().remove(cons);
if (!removed) {
throw new BuilderException("Unknown guard constraint: " + cons);
}
break;
}
}
- if (exist == false) {
- throw new BuilderException("No existing guard policy matching the id: " + id);
- }
- return this;
+ return exist;
}
@Override
public ControlLoopGuardBuilder removeAllLimitConstraints(String id) throws BuilderException {
- if (CLGuard.guards == null || CLGuard.guards.isEmpty()) {
+ if (cLGuard.getGuards() == null || cLGuard.getGuards().isEmpty()) {
throw new BuilderException("No guard policies exist");
}
if (id == null) {
throw new BuilderException("The id of target guard policy must not be null");
}
boolean exist = false;
- for (GuardPolicy policy: CLGuard.guards) {
- if (policy.id.equals(id)) {
+ for (GuardPolicy policy: cLGuard.getGuards()) {
+ if (policy.getId().equals(id)) {
exist = true;
- policy.limit_constraints.clear();
+ policy.getLimit_constraints().clear();
}
}
- if (exist == false) {
+ if (!exist) {
throw new BuilderException("No existing guard policy matching the id: " + id);
}
return this;
private class BuilderCompilerCallback implements ControlLoopCompilerCallback {
- public ResultsImpl results = new ResultsImpl();
+ private ResultsImpl results = new ResultsImpl();
@Override
public boolean onWarning(String message) {
@Override
public ControlLoopGuard getControlLoopGuard() {
- ControlLoopGuard guard = new ControlLoopGuard(this.CLGuard);
- return guard;
+ return new ControlLoopGuard(this.cLGuard);
}
options.setDefaultFlowStyle(FlowStyle.BLOCK);
options.setPrettyFlow(true);
Yaml yaml = new Yaml(options);
- String dumpedYaml = yaml.dump(CLGuard);
+ String dumpedYaml = yaml.dump(cLGuard);
//
// This is our callback class for our compiler
//
// Compile it
//
try {
- ControlLoopGuardCompiler.compile(CLGuard, callback);
+ ControlLoopGuardCompiler.compile(cLGuard, callback);
} catch (CompilerException e) {
callback.results.addMessage(new MessageImpl(e.getMessage(), MessageLevel.EXCEPTION));
}