YANGTOOLS-706: Split up base utility classes into rfc6020.util
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / 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.stmt.rfc6020.effective.type;
9
10 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
11 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
12 import org.opendaylight.yangtools.yang.model.util.type.BitBuilder;
13 import org.opendaylight.yangtools.yang.model.util.type.EnumPairBuilder;
14
15 final class EffectiveTypeUtil {
16     private EffectiveTypeUtil() {
17         throw new UnsupportedOperationException();
18     }
19
20     static Bit buildBit(final BitEffectiveStatementImpl stmt, final long effectivePos) {
21         // TODO: code duplication with EnumPairBuilder is indicating we could use a common Builder<?> interface
22         final BitBuilder builder = BitBuilder.create(stmt.getPath(), effectivePos).setStatus(stmt.getStatus());
23         stmt.getDescription().ifPresent(builder::setDescription);
24         stmt.getReference().ifPresent(builder::setReference);
25
26         return builder.build();
27     }
28
29     static EnumPair buildEnumPair(final EnumEffectiveStatementImpl stmt, final int effectiveValue) {
30         final EnumPairBuilder builder = EnumPairBuilder.create(stmt.getName(), effectiveValue)
31                 .setStatus(stmt.getStatus()).setUnknownSchemaNodes(stmt.getUnknownSchemaNodes());
32         stmt.getDescription().ifPresent(builder::setDescription);
33         stmt.getReference().ifPresent(builder::setReference);
34
35         return builder.build();
36     }
37 }