Reformulate StatementContextFactory.createEffective()
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / presence / PresenceStatementSupport.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, 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.presence;
9
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
12 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.PresenceEffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.PresenceStatement;
16 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStringStatementSupport;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
20
21 public final class PresenceStatementSupport
22         extends BaseStringStatementSupport<PresenceStatement, PresenceEffectiveStatement> {
23     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
24             SubstatementValidator.builder(YangStmtMapping.PRESENCE).build();
25     private static final PresenceStatementSupport INSTANCE = new PresenceStatementSupport();
26
27     private PresenceStatementSupport() {
28         super(YangStmtMapping.PRESENCE);
29     }
30
31     public static PresenceStatementSupport getInstance() {
32         return INSTANCE;
33     }
34
35     @Override
36     protected SubstatementValidator getSubstatementValidator() {
37         return SUBSTATEMENT_VALIDATOR;
38     }
39
40     @Override
41     protected PresenceStatement createDeclared(final StmtContext<String, PresenceStatement, ?> ctx,
42             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
43         return new RegularPresenceStatement(ctx.coerceRawStatementArgument(), substatements);
44     }
45
46     @Override
47     protected PresenceStatement createEmptyDeclared(final StmtContext<String, PresenceStatement, ?> ctx) {
48         return new EmptyPresenceStatement(ctx.coerceRawStatementArgument());
49     }
50
51     @Override
52     protected PresenceEffectiveStatement createEffective(final Current<String, PresenceStatement> stmt,
53             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
54         return substatements.isEmpty() ? new EmptyPresenceEffectiveStatement(stmt.declared())
55             : new RegularPresenceEffectiveStatement(stmt.declared(), substatements);
56     }
57 }