2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.groupbasedpolicy.dto;
\r
11 import javax.annotation.Nonnull;
\r
13 import org.opendaylight.groupbasedpolicy.api.ValidationResult;
\r
14 import org.opendaylight.yangtools.concepts.Builder;
\r
16 public final class ValidationResultBuilder implements Builder<ValidationResult> {
\r
18 private static final class ValidationResultImpl implements ValidationResult {
\r
20 private final boolean success;
\r
21 private final String message;
\r
23 private ValidationResultImpl(final boolean success, final String message) {
\r
24 this.success = success;
\r
25 this.message = message;
\r
29 public boolean isValid() {
\r
34 public String getMessage() {
\r
39 public boolean equals(Object o) {
\r
42 if (o == null || getClass() != o.getClass())
\r
45 ValidationResultImpl that = (ValidationResultImpl) o;
\r
47 if (success != that.success)
\r
49 return message.equals(that.message);
\r
53 public int hashCode() {
\r
54 int result = (success ? 1 : 0);
\r
55 result = 31 * result + message.hashCode();
\r
60 private boolean success;
\r
61 private String message = "";
\r
63 public ValidationResultBuilder success() {
\r
64 this.success = true;
\r
69 * Returns a builder for a failed result.
\r
71 public ValidationResultBuilder failed() {
\r
72 this.success = false;
\r
77 * Returns a builder for a failed result.
\r
79 * @param message brief explanation
\r
80 * @throws IllegalArgumentException when message is null
\r
82 public ValidationResultBuilder setMessage(@Nonnull String message) {
\r
83 if (message == null) {
\r
84 throw new IllegalArgumentException("Result message cannot be set to NULL!");
\r
86 this.message = message;
\r
91 public ValidationResult build() {
\r
92 return new ValidationResultImpl(success, message);
\r