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 org.opendaylight.yangtools.yang.model.api.MustDefinition;
11 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
13 import com.google.common.base.Optional;
14 import com.google.common.base.Preconditions;
18 * Immutable implementation of {@link MustDefinition}
21 public final class MustDefinitionImpl implements MustDefinition {
22 private final String mustStr;
23 private final String description;
24 private final String reference;
25 private final String errorAppTag;
26 private final String errorMessage;
30 * Creates new Must Definition
32 * @param mustStr must string statement, Must not be null.
33 * @param description Description of condition
34 * @param reference Reference for condition
35 * @param errorAppTag error application tag which should be used for error reporting when condition fails
36 * @param errorMessage message which should be used for error reporting when condition fails
37 * @deprecated Use {@link #create(String, Optional, Optional, Optional, Optional)} instead.
40 public MustDefinitionImpl(final String mustStr, final String description, final String reference, final String errorAppTag, final String errorMessage) {
41 this.mustStr = Preconditions.checkNotNull(mustStr);
42 this.description = description;
43 this.reference = reference;
44 this.errorAppTag = errorAppTag;
45 this.errorMessage = errorMessage;
50 * Creates new Must Definition
52 * @param mustStr must string statement, Must not be null.
53 * @param description Description of condition
54 * @param reference Reference for condition
55 * @param errorAppTag error application tag which should be used for error reporting when condition fails
56 * @param errorMessage message which should be used for error reporting when condition fails
58 public static MustDefinitionImpl create(final String mustStr, final Optional<String> description, final Optional<String> reference, final Optional<String> errorAppTag, final Optional<String> errorMessage) {
59 return new MustDefinitionImpl(mustStr, description.orNull(), reference.orNull(), errorAppTag.orNull(), errorMessage.orNull());
63 public String getDescription() {
68 public String getErrorAppTag() {
73 public String getErrorMessage() {
78 public String getReference() {
83 public RevisionAwareXPath getXpath() {
88 public int hashCode() {
91 result = prime * result + ((mustStr == null) ? 0 : mustStr.hashCode());
92 result = prime * result + ((description == null) ? 0 : description.hashCode());
93 result = prime * result + ((reference == null) ? 0 : reference.hashCode());
98 public boolean equals(final Object obj) {
105 if (getClass() != obj.getClass()) {
108 final MustDefinitionImpl other = (MustDefinitionImpl) obj;
109 if (mustStr == null) {
110 if (other.mustStr != null) {
113 } else if (!mustStr.equals(other.mustStr)) {
116 if (description == null) {
117 if (other.description != null) {
120 } else if (!description.equals(other.description)) {
123 if (reference == null) {
124 if (other.reference != null) {
127 } else if (!reference.equals(other.reference)) {
134 public String toString() {