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
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
10 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
12 import com.google.common.base.Optional;
13 import com.google.common.base.Preconditions;
15 public class PatternConstraintEffectiveImpl implements PatternConstraint {
17 private final String regEx;
18 private final String description;
19 private final String reference;
21 private final String errorAppTag;
22 private final String errorMessage;
24 public PatternConstraintEffectiveImpl(final String regex, final Optional<String> description,
25 final Optional<String> reference) {
29 this.regEx = Preconditions.checkNotNull(regex, "regex must not be null.");
30 this.description = description.orNull();
31 this.reference = reference.orNull();
33 errorAppTag = "invalid-regular-expression";
34 errorMessage = String.format("String %s is not valid regular expression.", regex);
38 public String getRegularExpression() {
43 public String getDescription() {
48 public String getErrorAppTag() {
53 public String getErrorMessage() {
58 public String getReference() {
63 public int hashCode() {
66 result = prime * result + ((description == null) ? 0 : description.hashCode());
67 result = prime * result + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
68 result = prime * result + ((errorMessage == null) ? 0 : errorMessage.hashCode());
69 result = prime * result + ((reference == null) ? 0 : reference.hashCode());
70 result = prime * result + regEx.hashCode();
75 public boolean equals(final Object obj) {
82 if (getClass() != obj.getClass()) {
85 final PatternConstraintEffectiveImpl other = (PatternConstraintEffectiveImpl) obj;
86 if (description == null) {
87 if (other.description != null) {
90 } else if (!description.equals(other.description)) {
93 if (errorAppTag == null) {
94 if (other.errorAppTag != null) {
97 } else if (!errorAppTag.equals(other.errorAppTag)) {
100 if (errorMessage == null) {
101 if (other.errorMessage != null) {
104 } else if (!errorMessage.equals(other.errorMessage)) {
107 if (reference == null) {
108 if (other.reference != null) {
111 } else if (!reference.equals(other.reference)) {
115 if (other.regEx != null) {
118 } else if (!regEx.equals(other.regEx)) {
125 public String toString() {
126 StringBuilder builder = new StringBuilder();
127 builder.append(PatternConstraintEffectiveImpl.class.getSimpleName());
128 builder.append(" [regex=");
129 builder.append(regEx);
130 builder.append(", description=");
131 builder.append(description);
132 builder.append(", reference=");
133 builder.append(reference);
134 builder.append(", errorAppTag=");
135 builder.append(errorAppTag);
136 builder.append(", errorMessage=");
137 builder.append(errorMessage);
139 return builder.toString();