Adjust test suite parser update to conform with API changes
[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.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;
17
18 @Beta
19 final class EffectiveTypeUtil {
20     private EffectiveTypeUtil() {
21         throw new UnsupportedOperationException();
22     }
23
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);
29
30         return builder.build();
31     }
32
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);
38
39         return builder.build();
40     }
41 }