2 * Copyright (c) 2015 Cisco Systems, Inc. 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.deviate;
10 import com.google.common.collect.Collections2;
11 import com.google.common.collect.ImmutableList;
12 import java.util.Collection;
13 import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
14 import org.opendaylight.yangtools.yang.model.api.DeviateKind;
15 import org.opendaylight.yangtools.yang.model.api.MustDefinition;
16 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
17 import org.opendaylight.yangtools.yang.model.api.UniqueConstraint;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ConfigEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.DefaultEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.DeviateEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.DeviateStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.MaxElementsEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.MinElementsEffectiveStatement;
26 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
27 import org.opendaylight.yangtools.yang.model.api.stmt.UnitsEffectiveStatement;
28 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement.DefaultArgument.WithSubstatements;
30 final class DeviateEffectiveStatementImpl extends WithSubstatements<DeviateKind, DeviateStatement>
31 implements DeviateDefinition, DeviateEffectiveStatement {
32 DeviateEffectiveStatementImpl(final DeviateStatement declared,
33 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
34 super(declared, substatements);
38 public DeviateKind getDeviateType() {
43 public Boolean getDeviatedConfig() {
44 return findFirstEffectiveSubstatementArgument(ConfigEffectiveStatement.class).orElse(null);
48 public String getDeviatedDefault() {
49 return findFirstEffectiveSubstatementArgument(DefaultEffectiveStatement.class).orElse(null);
53 public Boolean getDeviatedMandatory() {
54 return findFirstEffectiveSubstatementArgument(MandatoryEffectiveStatement.class).orElse(null);
58 public Integer getDeviatedMaxElements() {
59 return findFirstEffectiveSubstatementArgument(MaxElementsEffectiveStatement.class)
60 // FIXME: this does not handle 'unbounded'
61 .map(Integer::valueOf).orElse(null);
65 public Integer getDeviatedMinElements() {
66 return findFirstEffectiveSubstatementArgument(MinElementsEffectiveStatement.class).orElse(null);
70 public Collection<? extends MustDefinition> getDeviatedMusts() {
71 return allSubstatementsOfType(MustDefinition.class);
75 public TypeDefinition<?> getDeviatedType() {
76 return findFirstEffectiveSubstatement(TypeEffectiveStatement.class)
77 .map(TypeEffectiveStatement::getTypeDefinition).orElse(null);
81 public Collection<? extends UniqueConstraint> getDeviatedUniques() {
82 return allSubstatementsOfType(UniqueConstraint.class);
86 public String getDeviatedUnits() {
87 return findFirstEffectiveSubstatementArgument(UnitsEffectiveStatement.class).orElse(null);
90 @SuppressWarnings("unchecked")
91 private <T> Collection<T> allSubstatementsOfType(final Class<T> type) {
92 return Collection.class.cast(Collections2.filter(effectiveSubstatements(), type::isInstance));