AuditResult builder and enum adjustements.

keep-around/23b8b9e8830874d5f04b57600c3660bddce1287b
Pingex aka Raphaël 9 years ago
parent e1c38102f8
commit 913ff8d573

@ -1,5 +1,7 @@
package net.pingex.dcf.commands.audit; package net.pingex.dcf.commands.audit;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -76,15 +78,10 @@ public class AuditResult
} }
/** /**
* All the possible result codes for an andit and its component. * All the possible result codes for an andit.
*/ */
public enum ResultCode public enum ResultCode implements Comparable<ResultCode>
{ {
/**
* The test passed without any issue.
*/
PASS,
/** /**
* The audit failed. * The audit failed.
*/ */
@ -95,9 +92,76 @@ public class AuditResult
*/ */
WARN, WARN,
/**
* The test passed without any issue.
*/
PASS,
/** /**
* Test was ignored. * Test was ignored.
*/ */
NOOP NOOP
} }
/**
* Helper class to construct a proper AuditResult.
*/
public static class Builder
{
private ResultCode opcode;
private String message;
private List<Entry<IAuditComponentProvider, AuditResult>> subAuditsResults = new ArrayList<>();
public Builder setOpcode(ResultCode opcode)
{
this.opcode = opcode;
return this;
}
public Builder setMessage(String message)
{
this.message = message;
return this;
}
public Builder appendAuditResult(IAuditComponentProvider provider, AuditResult result)
{
appendAuditResult(new AbstractMap.SimpleEntry<IAuditComponentProvider, AuditResult>(provider, result));
return this;
}
public Builder appendAuditResult(Entry<IAuditComponentProvider, AuditResult> entry)
{
subAuditsResults.add(entry);
return this;
}
public List<Entry<IAuditComponentProvider, AuditResult>> getSubAuditsResults()
{
return subAuditsResults;
}
public ResultCode getOpcode()
{
return opcode;
}
public String getMessage()
{
return message;
}
public AuditResult build()
{
return new AuditResult(opcode, message, subAuditsResults.isEmpty() ? null : subAuditsResults);
}
}
/**
* Fork a new builder.
*/
public static Builder builder()
{
return new Builder();
}
} }