Improve KeyStatement implementations
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / key / AbstractKeyEffectiveStatement.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.key;
9
10 import java.util.Collection;
11 import org.opendaylight.yangtools.yang.model.api.stmt.KeyEffectiveStatement;
12 import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
13 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
14 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement;
15
16 abstract class AbstractKeyEffectiveStatement
17         extends AbstractDeclaredEffectiveStatement.Default<Collection<SchemaNodeIdentifier>, KeyStatement>
18         implements KeyEffectiveStatement {
19     abstract static class Foreign extends AbstractKeyEffectiveStatement {
20         // Polymorphic, with single value or a collection
21         private final Object argument;
22
23         Foreign(final KeyStatement declared, final Collection<SchemaNodeIdentifier> argument) {
24             super(declared);
25             this.argument = KeyStatementSupport.maskCollection(argument);
26         }
27
28         @Override
29         public final Collection<SchemaNodeIdentifier> argument() {
30             return KeyStatementSupport.unmaskCollection(argument);
31         }
32     }
33
34     abstract static class Local extends AbstractKeyEffectiveStatement {
35         Local(final KeyStatement declared) {
36             super(declared);
37         }
38
39         @Override
40         public final Collection<SchemaNodeIdentifier> argument() {
41             return getDeclared().argument();
42         }
43     }
44
45     AbstractKeyEffectiveStatement(final KeyStatement declared) {
46         super(declared);
47     }
48 }