Optimize simple declared statements
[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.StmtContext;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
19
20 public final class PresenceStatementSupport
21         extends BaseStringStatementSupport<PresenceStatement, PresenceEffectiveStatement> {
22     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
23             SubstatementValidator.builder(YangStmtMapping.PRESENCE).build();
24     private static final PresenceStatementSupport INSTANCE = new PresenceStatementSupport();
25
26     private PresenceStatementSupport() {
27         super(YangStmtMapping.PRESENCE);
28     }
29
30     public static PresenceStatementSupport getInstance() {
31         return INSTANCE;
32     }
33
34     @Override
35     public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
36         return value;
37     }
38
39     @Override
40     protected SubstatementValidator getSubstatementValidator() {
41         return SUBSTATEMENT_VALIDATOR;
42     }
43
44     @Override
45     protected PresenceStatement createDeclared(final StmtContext<String, PresenceStatement, ?> ctx,
46             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
47         return new RegularPresenceStatement(ctx, substatements);
48     }
49
50     @Override
51     protected PresenceStatement createEmptyDeclared(final StmtContext<String, PresenceStatement, ?> ctx) {
52         return new EmptyPresenceStatement(ctx);
53     }
54
55     @Override
56     protected PresenceEffectiveStatement createEffective(
57             final StmtContext<String, PresenceStatement, PresenceEffectiveStatement> ctx,
58             final PresenceStatement declared,
59             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
60         return new RegularPresenceEffectiveStatement(declared, substatements);
61     }
62
63     @Override
64     protected PresenceEffectiveStatement createEmptyEffective(
65             final StmtContext<String, PresenceStatement, PresenceEffectiveStatement> ctx,
66             final PresenceStatement declared) {
67         return new EmptyPresenceEffectiveStatement(declared);
68     }
69 }