2 * Copyright (c) 2014 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
8 package org.opendaylight.yangtools.yang.model.util;
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.concepts.Immutable;
14 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
17 * {@link Immutable} implementation of {@link PatternConstraint}
19 * Creates an instance of Range constraint based on supplied parameters with
20 * additional behaviour:
23 * <li>{@link PatternConstraint#getErrorAppTag()} returns
24 * <code>invalid-regular-expression</code>
28 final class PatternConstraintImpl implements PatternConstraint, Immutable {
30 private final String regex;
31 private final String description;
32 private final String reference;
34 private final String errorAppTag;
35 private final String errorMessage;
37 public PatternConstraintImpl(final String regex, final Optional<String> description,
38 final Optional<String> reference) {
40 this.regex = Preconditions.checkNotNull(regex, "regex must not be null.");
41 this.description = description.orNull();
42 this.reference = reference.orNull();
44 // FIXME: Lookup better suitable error tag.
45 errorAppTag = "invalid-regular-expression";
46 // TODO: add erro message
51 public String getDescription() {
56 public String getErrorAppTag() {
61 public String getErrorMessage() {
66 public String getReference() {
71 public String getRegularExpression() {
76 public int hashCode() {
79 result = prime * result + Objects.hashCode(description);
80 result = prime * result + Objects.hashCode(errorAppTag);
81 result = prime * result + Objects.hashCode(errorMessage);
82 result = prime * result + Objects.hashCode(reference);
83 result = prime * result + regex.hashCode();
88 public boolean equals(final Object obj) {
95 if (getClass() != obj.getClass()) {
98 final PatternConstraintImpl other = (PatternConstraintImpl) obj;
99 if (description == null) {
100 if (other.description != null) {
103 } else if (!description.equals(other.description)) {
106 if (errorAppTag == null) {
107 if (other.errorAppTag != null) {
110 } else if (!errorAppTag.equals(other.errorAppTag)) {
113 if (errorMessage == null) {
114 if (other.errorMessage != null) {
117 } else if (!errorMessage.equals(other.errorMessage)) {
120 if (reference == null) {
121 if (other.reference != null) {
124 } else if (!reference.equals(other.reference)) {
128 if (other.regex != null) {
131 } else if (!regex.equals(other.regex)) {
138 public String toString() {
139 StringBuilder builder = new StringBuilder();
140 builder.append("PatternConstraintImpl [regex=");
141 builder.append(regex);
142 builder.append(", description=");
143 builder.append(description);
144 builder.append(", reference=");
145 builder.append(reference);
146 builder.append(", errorAppTag=");
147 builder.append(errorAppTag);
148 builder.append(", errorMessage=");
149 builder.append(errorMessage);
151 return builder.toString();