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.model.ri.stmt.impl.eff;
10 import static com.google.common.base.Verify.verify;
12 import com.google.common.collect.ImmutableSet;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.stmt.KeyEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
18 import org.opendaylight.yangtools.yang.model.spi.meta.AbstractDeclaredEffectiveStatement;
20 abstract class AbstractKeyEffectiveStatement
21 extends AbstractDeclaredEffectiveStatement.Default<Set<QName>, KeyStatement>
22 implements KeyEffectiveStatement {
23 abstract static class Foreign extends AbstractKeyEffectiveStatement {
24 // Polymorphic, with single value or a collection
25 private final Object argument;
27 Foreign(final KeyStatement declared, final Set<QName> argument) {
29 this.argument = maskSet(argument);
33 public final Set<QName> argument() {
34 return unmaskSet(argument);
37 private static @NonNull Object maskSet(final @NonNull Set<QName> set) {
38 return set.size() == 1 ? set.iterator().next() : set;
41 @SuppressWarnings("unchecked")
42 private static @NonNull Set<QName> unmaskSet(final @NonNull Object masked) {
43 if (masked instanceof Set) {
44 return (Set<QName>) masked;
46 verify(masked instanceof QName, "Unexpected argument %s", masked);
47 return ImmutableSet.of((QName) masked);
51 abstract static class Local extends AbstractKeyEffectiveStatement {
52 Local(final KeyStatement declared) {
57 public final Set<QName> argument() {
58 return getDeclared().argument();
62 AbstractKeyEffectiveStatement(final KeyStatement declared) {