DeclaredStatements can contain default implementations
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / config / 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.rfc7950.stmt.config;
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.YangStmtMapping;
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 argument() {
25             return Boolean.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 argument() {
37             return Boolean.TRUE;
38         }
39
40         @Override
41         EffectiveStatement<Boolean, ConfigStatement> toEffective() {
42             return EmptyConfigEffectiveStatement.TRUE;
43         }
44     };
45
46     abstract EffectiveStatement<Boolean, ConfigStatement> toEffective();
47
48     @Nonnull
49     @Override
50     public final Collection<? extends DeclaredStatement<?>> declaredSubstatements() {
51         return ImmutableList.of();
52     }
53
54     @Nonnull
55     @Override
56     public final StatementDefinition statementDefinition() {
57         return YangStmtMapping.CONFIG;
58     }
59
60     @Override
61     public final String rawArgument() {
62         return Boolean.toString(getValue());
63     }
64
65     @Nonnull
66     @Override
67     public final StatementSource getStatementSource() {
68         return StatementSource.DECLARATION;
69     }
70
71     @Override
72     public final int hashCode() {
73         return Objects.hash(statementDefinition(), getStatementSource(), argument(), rawArgument(),
74             declaredSubstatements(), getValue());
75     }
76
77     @Override
78     public final boolean equals(final Object obj) {
79         if (this == obj) {
80             return true;
81         }
82         if (!(obj instanceof ConfigStatement)) {
83             return false;
84         }
85
86         final ConfigStatement other = (ConfigStatement) obj;
87
88         return getValue() == other.getValue() && argument().equals(other.argument())
89                 && rawArgument().equals(other.rawArgument())
90                 && statementDefinition().equals(other.statementDefinition())
91                 && getStatementSource().equals(other.getStatementSource())
92                 && declaredSubstatements().equals(other.declaredSubstatements());
93     }
94 }