Merge branch 'master' of ../controller
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / type / EffectiveTypeUtil.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.type;
9
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
13 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
14 import org.opendaylight.yangtools.yang.model.util.type.BitBuilder;
15 import org.opendaylight.yangtools.yang.model.util.type.EnumPairBuilder;
16 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.bit.BitEffectiveStatementImpl;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.enum_.EnumEffectiveStatementImpl;
18
19 @Beta
20 final class EffectiveTypeUtil {
21     private EffectiveTypeUtil() {
22         throw new UnsupportedOperationException();
23     }
24
25     static @NonNull Bit buildBit(final @NonNull BitEffectiveStatementImpl stmt, final long effectivePos) {
26         // TODO: code duplication with EnumPairBuilder is indicating we could use a common Builder<?> interface
27         final BitBuilder builder = BitBuilder.create(stmt.getPath(), effectivePos).setStatus(stmt.getStatus());
28         stmt.getDescription().ifPresent(builder::setDescription);
29         stmt.getReference().ifPresent(builder::setReference);
30
31         return builder.build();
32     }
33
34     static @NonNull EnumPair buildEnumPair(final @NonNull EnumEffectiveStatementImpl stmt, final int effectiveValue) {
35         final EnumPairBuilder builder = EnumPairBuilder.create(stmt.getName(), effectiveValue)
36                 .setStatus(stmt.getStatus()).setUnknownSchemaNodes(stmt.getUnknownSchemaNodes());
37         stmt.getDescription().ifPresent(builder::setDescription);
38         stmt.getReference().ifPresent(builder::setReference);
39
40         return builder.build();
41     }
42 }