2 * Copyright (c) 2017 Pantheon Technologies, 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.parser.rfc7950.stmt.type;
10 import com.google.common.annotations.Beta;
11 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
12 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
13 import org.opendaylight.yangtools.yang.model.util.type.BitBuilder;
14 import org.opendaylight.yangtools.yang.model.util.type.EnumPairBuilder;
15 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.bit.BitEffectiveStatementImpl;
16 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.enum_.EnumEffectiveStatementImpl;
19 final class EffectiveTypeUtil {
20 private EffectiveTypeUtil() {
21 throw new UnsupportedOperationException();
24 static Bit buildBit(final BitEffectiveStatementImpl stmt, final long effectivePos) {
25 // TODO: code duplication with EnumPairBuilder is indicating we could use a common Builder<?> interface
26 final BitBuilder builder = BitBuilder.create(stmt.getPath(), effectivePos).setStatus(stmt.getStatus());
27 stmt.getDescription().ifPresent(builder::setDescription);
28 stmt.getReference().ifPresent(builder::setReference);
30 return builder.build();
33 static EnumPair buildEnumPair(final EnumEffectiveStatementImpl stmt, final int effectiveValue) {
34 final EnumPairBuilder builder = EnumPairBuilder.create(stmt.getName(), effectiveValue)
35 .setStatus(stmt.getStatus()).setUnknownSchemaNodes(stmt.getUnknownSchemaNodes());
36 stmt.getDescription().ifPresent(builder::setDescription);
37 stmt.getReference().ifPresent(builder::setReference);
39 return builder.build();