2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.groupbasedpolicy.resolver.validator;
11 import java.util.ArrayList;
12 import java.util.List;
15 * Class to hold validation results of object and his children.
18 public class ValidationResult {
21 * Enumeration of possible results.
30 * Base validation failed
34 * Validation of (any) child failed
38 * Base validation and validation of (any) child failed
40 FAIL_BASE_AND_CHILD(false);
42 private boolean value;
44 Result(boolean value) {
48 public boolean getValue() {
54 * Variable to store result of validation. The final result is based on base
55 * status and status of all children.
57 private Result result = Result.SUCCESS;
60 * Class of {@link Validator}, which returns result.
62 private final Class<? extends Validator> validatorClass;
65 * List of all children validations.
67 private List<ValidationResult> childResults = new ArrayList<>();
70 * Human-readable description of current status.
72 private String description;
75 * Create new {@link ValidationResult} to store result of validation.
77 * @param validatorClass Creator of {@link ValidationResult}
79 public ValidationResult(Class<? extends Validator> validatorClass) {
80 this.validatorClass = validatorClass;
85 * @return Current result
87 public Result getResult() {
93 * @param result Result to set
95 public void setResult(Result result) {
101 * @return List of result child objects
103 public List<ValidationResult> getChildResults() {
108 * Add new child result. Result of his parent is based on status of base and
113 public void addChildResult(ValidationResult childResult) {
114 if (!childResult.getResult().getValue()) {
116 //if validation already failed for base or child
117 if (this.getResult().equals(ValidationResult.Result.FAIL_BASE)
118 || this.getResult().equals(ValidationResult.Result.FAIL_BASE_AND_CHILD)) {
119 this.setResult(ValidationResult.Result.FAIL_BASE_AND_CHILD);
121 //if validation failed only for child
123 this.setResult(ValidationResult.Result.FAIL_CHILD);
127 this.childResults.add(childResult);
131 * Returns {@link Validator} class in which the result arises.
133 * @return {@link Validator} class
135 public Class<? extends Validator> getValidatorClass() {
136 return validatorClass;
141 * @return Current result description
143 public String getDescription() {
148 * Set human-readable description of result.
150 * @param description Result description to set
152 public void setDescription(String description) {
153 this.description = description;