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.model.ri.stmt.impl.eff;
10 import com.google.common.collect.Collections2;
11 import com.google.common.collect.ImmutableList;
12 import java.util.Collection;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
15 import org.opendaylight.yangtools.yang.model.api.DeviateKind;
16 import org.opendaylight.yangtools.yang.model.api.MustDefinition;
17 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
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.UniqueEffectiveStatement;
28 import org.opendaylight.yangtools.yang.model.api.stmt.UnitsEffectiveStatement;
29 import org.opendaylight.yangtools.yang.model.spi.meta.AbstractDeclaredEffectiveStatement.DefaultArgument.WithSubstatements;
31 public final class DeviateEffectiveStatementImpl extends WithSubstatements<DeviateKind, DeviateStatement>
32 implements DeviateDefinition, DeviateEffectiveStatement {
33 public DeviateEffectiveStatementImpl(final DeviateStatement declared,
34 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
35 super(declared, substatements);
39 public DeviateKind getDeviateType() {
44 public Boolean getDeviatedConfig() {
45 return findFirstEffectiveSubstatementArgument(ConfigEffectiveStatement.class).orElse(null);
49 public String getDeviatedDefault() {
50 return findFirstEffectiveSubstatementArgument(DefaultEffectiveStatement.class).orElse(null);
54 public Boolean getDeviatedMandatory() {
55 return findFirstEffectiveSubstatementArgument(MandatoryEffectiveStatement.class).orElse(null);
59 public Integer getDeviatedMaxElements() {
60 return findFirstEffectiveSubstatementArgument(MaxElementsEffectiveStatement.class)
61 // FIXME: this does not handle 'unbounded'
62 .map(Integer::valueOf).orElse(null);
66 public Integer getDeviatedMinElements() {
67 return findFirstEffectiveSubstatementArgument(MinElementsEffectiveStatement.class).orElse(null);
71 public Collection<? extends @NonNull MustDefinition> getDeviatedMusts() {
72 return allSubstatementsOfType(MustDefinition.class);
76 public TypeDefinition<?> getDeviatedType() {
77 return findFirstEffectiveSubstatement(TypeEffectiveStatement.class)
78 .map(TypeEffectiveStatement::getTypeDefinition).orElse(null);
82 public Collection<? extends @NonNull UniqueEffectiveStatement> getDeviatedUniques() {
83 return allSubstatementsOfType(UniqueEffectiveStatement.class);
87 public String getDeviatedUnits() {
88 return findFirstEffectiveSubstatementArgument(UnitsEffectiveStatement.class).orElse(null);
92 public DeviateEffectiveStatement asEffectiveStatement() {
96 @SuppressWarnings("unchecked")
97 private <T> Collection<T> allSubstatementsOfType(final Class<T> type) {
98 return Collection.class.cast(Collections2.filter(effectiveSubstatements(), type::isInstance));