2 * Copyright (c) 2013 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 org.opendaylight.yangtools.yang.model.api.MustDefinition;
13 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
16 * Immutable implementation of {@link MustDefinition}
18 public final class MustDefinitionImpl implements MustDefinition {
19 private final String mustStr;
20 private final String description;
21 private final String reference;
22 private final String errorAppTag;
23 private final String errorMessage;
26 * Creates new Must Definition
28 * @param mustStr must string statement, Must not be null.
29 * @param description Description of condition
30 * @param reference Reference for condition
31 * @param errorAppTag error application tag which should be used for error reporting when condition fails
32 * @param errorMessage message which should be used for error reporting when condition fails
34 private MustDefinitionImpl(final String mustStr, final String description, final String reference, final String errorAppTag, final String errorMessage) {
35 this.mustStr = Preconditions.checkNotNull(mustStr);
36 this.description = description;
37 this.reference = reference;
38 this.errorAppTag = errorAppTag;
39 this.errorMessage = errorMessage;
44 * Creates new Must Definition
46 * @param mustStr must string statement, Must not be null.
47 * @param description Description of condition
48 * @param reference Reference for condition
49 * @param errorAppTag error application tag which should be used for error reporting when condition fails
50 * @param errorMessage message which should be used for error reporting when condition fails
52 public static MustDefinitionImpl create(final String mustStr, final Optional<String> description,
53 final Optional<String> reference, final Optional<String> errorAppTag, final Optional<String> errorMessage) {
54 return new MustDefinitionImpl(mustStr, description.orNull(), reference.orNull(), errorAppTag.orNull(), errorMessage.orNull());
58 public String getDescription() {
63 public String getErrorAppTag() {
68 public String getErrorMessage() {
73 public String getReference() {
78 public RevisionAwareXPath getXpath() {
83 public int hashCode() {
86 result = prime * result + ((mustStr == null) ? 0 : mustStr.hashCode());
87 result = prime * result + ((description == null) ? 0 : description.hashCode());
88 result = prime * result + ((reference == null) ? 0 : reference.hashCode());
93 public boolean equals(final Object obj) {
100 if (getClass() != obj.getClass()) {
103 final MustDefinitionImpl other = (MustDefinitionImpl) obj;
104 if (mustStr == null) {
105 if (other.mustStr != null) {
108 } else if (!mustStr.equals(other.mustStr)) {
111 if (description == null) {
112 if (other.description != null) {
115 } else if (!description.equals(other.description)) {
118 if (reference == null) {
119 if (other.reference != null) {
122 } else if (!reference.equals(other.reference)) {
129 public String toString() {