2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.key;
10 import static com.google.common.base.Verify.verify;
12 import com.google.common.collect.ImmutableSet;
13 import java.util.Collection;
14 import org.opendaylight.yangtools.yang.model.api.stmt.KeyEffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement;
19 abstract class AbstractKeyEffectiveStatement
20 extends AbstractDeclaredEffectiveStatement.Default<Collection<SchemaNodeIdentifier>, KeyStatement>
21 implements KeyEffectiveStatement {
22 abstract static class Foreign extends AbstractKeyEffectiveStatement {
23 // Polymorphic, with single value or a collection
24 private final Object argument;
26 Foreign(final KeyStatement declared, final Collection<SchemaNodeIdentifier> argument) {
28 this.argument = argument.size() == 1 ? argument.iterator().next() : argument;
32 @SuppressWarnings("unchecked")
33 public final Collection<SchemaNodeIdentifier> argument() {
34 if (argument instanceof Collection) {
35 return (Collection<SchemaNodeIdentifier>) argument;
37 verify(argument instanceof SchemaNodeIdentifier, "Unexpected argument %s", argument);
38 return ImmutableSet.of((SchemaNodeIdentifier) argument);
42 abstract static class Local extends AbstractKeyEffectiveStatement {
43 Local(final KeyStatement declared) {
48 public final Collection<SchemaNodeIdentifier> argument() {
49 return getDeclared().argument();
53 AbstractKeyEffectiveStatement(final KeyStatement declared) {