Use Objects.equals() in effective statements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / MustEffectiveStatementImpl.java
1 /**
2  * Copyright (c) 2015 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.parser.stmt.rfc6020.effective;
9
10 import java.util.Objects;
11 import org.opendaylight.yangtools.yang.model.api.MustDefinition;
12 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.MustStatement;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
16
17 public class MustEffectiveStatementImpl extends EffectiveStatementBase<RevisionAwareXPath, MustStatement> implements
18         MustDefinition {
19
20     private final RevisionAwareXPath xPath;
21     private String description;
22     private String errorAppTag;
23     private String errorMessage;
24     private String reference;
25
26     public MustEffectiveStatementImpl(final StmtContext<RevisionAwareXPath, MustStatement, ?> ctx) {
27         super(ctx);
28
29         initFields();
30
31         xPath = ctx.getStatementArgument();
32     }
33
34     private void initFields() {
35
36         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
37
38             if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
39                 description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
40             }
41             if (effectiveStatement instanceof ErrorAppTagEffectiveStatementImpl) {
42                 errorAppTag = ((ErrorAppTagEffectiveStatementImpl) effectiveStatement).argument();
43             }
44             if (effectiveStatement instanceof ErrorMessageEffectiveStatementImpl) {
45                 errorMessage = ((ErrorMessageEffectiveStatementImpl) effectiveStatement).argument();
46             }
47             if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
48                 reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
49             }
50         }
51     }
52
53     @Override
54     public RevisionAwareXPath getXpath() {
55         return xPath;
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 int hashCode() {
80         final int prime = 31;
81         int result = 1;
82         result = prime * result + Objects.hashCode(xPath);
83         result = prime * result + Objects.hashCode(description);
84         result = prime * result + Objects.hashCode(reference);
85         return result;
86     }
87
88     @Override
89     public boolean equals(final Object obj) {
90         if (this == obj) {
91             return true;
92         }
93         if (obj == null) {
94             return false;
95         }
96         if (getClass() != obj.getClass()) {
97             return false;
98         }
99         final MustEffectiveStatementImpl other = (MustEffectiveStatementImpl) obj;
100         if (!Objects.equals(xPath, other.xPath)) {
101             return false;
102         }
103         if (!Objects.equals(description, other.description)) {
104             return false;
105         }
106         if (!Objects.equals(reference,other.reference)) {
107             return false;
108         }
109         return true;
110     }
111
112     @Override
113     public String toString() {
114         return xPath.toString();
115     }
116 }