Reduce cyclomatic complexity
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / MustDefinitionImpl.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.util;
9
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;
15
16 /**
17  * Immutable implementation of {@link MustDefinition}
18  */
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;
25
26     /**
27      * Creates new Must Definition
28      *
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
34      */
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;
41     }
42
43     /**
44     *
45     * Creates new Must Definition
46     *
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
52     */
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());
56     }
57
58     @Override
59     public String getDescription() {
60         return description;
61     }
62
63     @Override
64     public String getErrorAppTag() {
65         return errorAppTag;
66     }
67
68     @Override
69     public String getErrorMessage() {
70         return errorMessage;
71     }
72
73     @Override
74     public String getReference() {
75         return reference;
76     }
77
78     @Override
79     public RevisionAwareXPath getXpath() {
80         return null;
81     }
82
83     @Override
84     public int hashCode() {
85         final int prime = 31;
86         int result = 1;
87         result = prime * result + mustStr.hashCode();
88         result = prime * result + Objects.hashCode(description);
89         result = prime * result + Objects.hashCode(reference);
90         return result;
91     }
92
93     @Override
94     public boolean equals(final Object obj) {
95         if (this == obj) {
96             return true;
97         }
98         if (!(obj instanceof MustDefinitionImpl)) {
99             return false;
100         }
101         final MustDefinitionImpl other = (MustDefinitionImpl) obj;
102         return mustStr.equals(other.mustStr) && Objects.equals(description, other.description)
103                 && Objects.equals(reference, other.reference);
104     }
105
106     @Override
107     public String toString() {
108         return mustStr;
109     }
110 }