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 rawRegEx;
21 private final String description;
22 private final String reference;
23 private final String errorAppTag;
24 private final String errorMessage;
25 private final ModifierKind modifier;
27 public PatternConstraintEffectiveImpl(final String regex, final String rawRegex,
28 final Optional<String> description, final Optional<String> reference) {
29 this(regex, rawRegex, description.orNull(), reference.orNull(), null, null, null);
32 public PatternConstraintEffectiveImpl(final String regex, final String rawRegex, final String description,
33 final String reference, final String errorAppTag, final String errorMessage, final ModifierKind modifier) {
34 this.regEx = Preconditions.checkNotNull(regex, "regex must not be null.");
35 this.rawRegEx = Preconditions.checkNotNull(rawRegex, "raw regex must not be null.");
36 this.description = description;
37 this.reference = reference;
38 this.errorAppTag = errorAppTag != null ? errorAppTag : "invalid-regular-expression";
39 this.errorMessage = errorMessage != null ? errorMessage : String.format(
40 "Supplied value does not match the regular expression %s.", regex);
41 this.modifier = modifier;
45 public String getRegularExpression() {
50 public String getRawRegularExpression() {
55 public String getDescription() {
60 public String getErrorAppTag() {
65 public String getErrorMessage() {
70 public ModifierKind getModifier() {
75 public String getReference() {
80 public int hashCode() {
81 return Objects.hash(description, errorAppTag, errorMessage, reference, regEx, modifier);
85 public boolean equals(final Object obj) {
92 if (getClass() != obj.getClass()) {
95 final PatternConstraintEffectiveImpl other = (PatternConstraintEffectiveImpl) 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) && Objects.equals(modifier, other.modifier);
102 public String toString() {
103 return MoreObjects.toStringHelper(this).add("regex", regEx).add("description", description)
104 .add("reference", reference).add("errorAppTag", errorAppTag).add("errorMessage", errorMessage)
105 .add("modifier", modifier).toString();