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 com.google.common.base.MoreObjects;
11 import com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13 import java.util.Objects;
14 import org.opendaylight.yangtools.yang.model.api.type.ModifierKind;
15 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
17 public class PatternConstraintEffectiveImpl implements PatternConstraint {
19 private final String regEx;
20 private final String description;
21 private final String reference;
22 private final String errorAppTag;
23 private final String errorMessage;
24 private final ModifierKind modifier;
26 public PatternConstraintEffectiveImpl(final String regex, final Optional<String> description,
27 final Optional<String> reference) {
28 this(regex, description.orNull(), reference.orNull(), null, null, null);
31 public PatternConstraintEffectiveImpl(final String regex, final String description, final String reference,
32 final String errorAppTag, final String errorMessage, final ModifierKind modifier) {
34 this.regEx = Preconditions.checkNotNull(regex, "regex must not be null.");
35 this.description = description;
36 this.reference = reference;
37 this.errorAppTag = errorAppTag != null ? errorAppTag : "invalid-regular-expression";
38 this.errorMessage = errorMessage != null ? errorMessage : String.format(
39 "Supplied value does not match the regular expression %s.", regex);
40 this.modifier = modifier;
44 public String getRegularExpression() {
49 public String getDescription() {
54 public String getErrorAppTag() {
59 public String getErrorMessage() {
64 public ModifierKind getModifier() {
69 public String getReference() {
74 public int hashCode() {
75 return Objects.hash(description, errorAppTag, errorMessage, reference, regEx, modifier);
79 public boolean equals(final Object obj) {
86 if (getClass() != obj.getClass()) {
89 final PatternConstraintEffectiveImpl other = (PatternConstraintEffectiveImpl) obj;
90 return Objects.equals(description, other.description) && Objects.equals(errorAppTag, other.errorAppTag)
91 && Objects.equals(errorMessage, other.errorMessage) && Objects.equals(reference, other.reference)
92 && Objects.equals(regEx, other.regEx) && Objects.equals(modifier, other.modifier);
96 public String toString() {
97 return MoreObjects.toStringHelper(this).add("regex", regEx).add("description", description)
98 .add("reference", reference).add("errorAppTag", errorAppTag).add("errorMessage", errorMessage)
99 .add("modifier", modifier).toString();