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 java.util.Objects;
13 import org.opendaylight.yangtools.yang.model.api.MustDefinition;
14 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
17 * Immutable implementation of {@link MustDefinition}
19 public final class MustDefinitionImpl implements MustDefinition {
20 private final String mustStr;
21 private final String description;
22 private final String reference;
23 private final String errorAppTag;
24 private final String errorMessage;
27 * Creates new Must Definition
29 * @param mustStr must string statement, Must not be null.
30 * @param description Description of condition
31 * @param reference Reference for condition
32 * @param errorAppTag error application tag which should be used for error reporting when condition fails
33 * @param errorMessage message which should be used for error reporting when condition fails
35 private MustDefinitionImpl(final String mustStr, final String description, final String reference, final String errorAppTag, final String errorMessage) {
36 this.mustStr = Preconditions.checkNotNull(mustStr);
37 this.description = description;
38 this.reference = reference;
39 this.errorAppTag = errorAppTag;
40 this.errorMessage = errorMessage;
45 * Creates new Must Definition
47 * @param mustStr must string statement, Must not be null.
48 * @param description Description of condition
49 * @param reference Reference for condition
50 * @param errorAppTag error application tag which should be used for error reporting when condition fails
51 * @param errorMessage message which should be used for error reporting when condition fails
53 public static MustDefinitionImpl create(final String mustStr, final Optional<String> description,
54 final Optional<String> reference, final Optional<String> errorAppTag, final Optional<String> errorMessage) {
55 return new MustDefinitionImpl(mustStr, description.orNull(), reference.orNull(), errorAppTag.orNull(), errorMessage.orNull());
59 public String getDescription() {
64 public String getErrorAppTag() {
69 public String getErrorMessage() {
74 public String getReference() {
79 public RevisionAwareXPath getXpath() {
84 public int hashCode() {
87 result = prime * result + Objects.hashCode(mustStr);
88 result = prime * result + Objects.hashCode(description);
89 result = prime * result + Objects.hashCode(reference);
94 public boolean equals(final Object obj) {
101 if (getClass() != obj.getClass()) {
104 final MustDefinitionImpl other = (MustDefinitionImpl) obj;
105 if (!Objects.equals(mustStr, other.mustStr)) {
108 if (!Objects.equals(description, other.description)) {
111 if (!Objects.equals(reference, other.reference)) {
118 public String toString() {