Propagate @Nonnull and @Nullable annotations
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / EmptyConfigStatement.java
1 /**
2  * Copyright (c) 2016 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;
9
10 import com.google.common.collect.ImmutableList;
11 import java.util.Collection;
12 import java.util.Objects;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
15 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
18 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
20
21 abstract class EmptyConfigStatement implements ConfigStatement {
22     static final ConfigStatement FALSE = new EmptyConfigStatement() {
23         @Override
24         public boolean getValue() {
25             return false;
26         }
27
28         @Override
29         EffectiveStatement<Boolean, ConfigStatement> toEffective() {
30             return EmptyConfigEffectiveStatement.FALSE;
31         }
32     };
33
34     static final ConfigStatement TRUE = new EmptyConfigStatement() {
35         @Override
36         public boolean getValue() {
37             return true;
38         }
39
40         @Override
41         EffectiveStatement<Boolean, ConfigStatement> toEffective() {
42             return EmptyConfigEffectiveStatement.TRUE;
43         }
44     };
45
46     private EmptyConfigStatement() {
47         // Invisible on purpose
48     }
49
50     abstract EffectiveStatement<Boolean, ConfigStatement> toEffective();
51
52     @Nonnull
53     @Override
54     public final Collection<? extends DeclaredStatement<?>> declaredSubstatements() {
55         return ImmutableList.of();
56     }
57
58     @Nonnull
59     @Override
60     public final StatementDefinition statementDefinition() {
61         return Rfc6020Mapping.CONFIG;
62     }
63
64     @Override
65     public final String rawArgument() {
66         return Boolean.toString(getValue());
67     }
68
69     @Override
70     public final Boolean argument() {
71         return Boolean.valueOf(getValue());
72     }
73
74     @Nonnull
75     @Override
76     public final StatementSource getStatementSource() {
77         return StatementSource.DECLARATION;
78     }
79
80     @Override
81     public final int hashCode() {
82         return Objects.hash(statementDefinition(), getStatementSource(), argument(),
83             rawArgument(), declaredSubstatements(), getValue());
84     }
85
86     @Override
87     public final boolean equals(final Object obj) {
88         if (this == obj) {
89             return true;
90         }
91         if (!(obj instanceof ConfigStatement)) {
92             return false;
93         }
94
95         final ConfigStatement other = (ConfigStatement) obj;
96
97         return  getValue() == other.getValue() && argument().equals(other.argument()) &&
98                 rawArgument().equals(other.rawArgument()) &&
99                 statementDefinition().equals(other.statementDefinition()) &&
100                 getStatementSource().equals(other.getStatementSource()) &&
101                 declaredSubstatements().equals(other.declaredSubstatements());
102     }
103 }