1 package org.opendaylight.groupbasedpolicy.resolver.validator;
4 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
6 * This program and the accompanying materials are made available under the
7 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 import java.util.ArrayList;
11 import java.util.List;
14 * Class to hold validation results of object and his children.
17 public class ValidationResult {
20 * Enumeration of possible results.
29 * Base validation failed
33 * Validation of (any) child failed
37 * Base validation and validation of (any) child failed
39 FAIL_BASE_AND_CHILD(false);
41 private boolean value;
43 Result(boolean value) {
47 public boolean getValue() {
53 * Variable to store result of validation. The final result is based on base
54 * status and status of all children.
56 private Result result = Result.SUCCESS;
59 * Class of {@link Validator}, which returns result.
61 private final Class<? extends Validator> validatorClass;
64 * List of all children validations.
66 private List<ValidationResult> childResults = new ArrayList<>();
69 * Human-readable description of current status.
71 private String description;
74 * Create new {@link ValidationResult} to store result of validation.
76 * @param validatorClass Creator of {@link ValidationResult}
78 public ValidationResult(Class<? extends Validator> validatorClass) {
79 this.validatorClass = validatorClass;
84 * @return Current result
86 public Result getResult() {
92 * @param result Result to set
94 public void setResult(Result result) {
100 * @return List of result child objects
102 public List<ValidationResult> getChildResults() {
107 * Add new child result. Result of his parent is based on status of base and
112 public void addChildResult(ValidationResult childResult) {
113 if (!childResult.getResult().getValue()) {
115 //if validation already failed for base or child
116 if (this.getResult().equals(ValidationResult.Result.FAIL_BASE)
117 || this.getResult().equals(ValidationResult.Result.FAIL_BASE_AND_CHILD)) {
118 this.setResult(ValidationResult.Result.FAIL_BASE_AND_CHILD);
120 //if validation failed only for child
122 this.setResult(ValidationResult.Result.FAIL_CHILD);
126 this.childResults.add(childResult);
130 * Returns {@link Validator} class in which the result arises.
132 * @return {@link Validator} class
134 public Class<? extends Validator> getValidatorClass() {
135 return validatorClass;
140 * @return Current result description
142 public String getDescription() {
147 * Set human-readable description of result.
149 * @param description Result description to set
151 public void setDescription(String description) {
152 this.description = description;