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) {
92 if (!(obj instanceof PatternConstraintImpl)) {
95 final PatternConstraintImpl other = (PatternConstraintImpl) obj;
96 return Objects.equals(description, other.description) && Objects.equals(errorAppTag, other.errorAppTag)
97 && Objects.equals(errorMessage, other.errorMessage) && Objects.equals(reference, other.reference)
98 && Objects.equals(regex, other.regex);
102 public String toString() {
103 StringBuilder builder = new StringBuilder();
104 builder.append("PatternConstraintImpl [regex=");
105 builder.append(regex);
106 builder.append(", description=");
107 builder.append(description);
108 builder.append(", reference=");
109 builder.append(reference);
110 builder.append(", errorAppTag=");
111 builder.append(errorAppTag);
112 builder.append(", errorMessage=");
113 builder.append(errorMessage);
115 return builder.toString();