import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@Test
public void fromNormalizedNodeTest() throws Exception {
final SchemaContext schemaCtx = YangParserTestUtils.parseYangResource("/test.yang");
- final NormalizedNode<?, ?> data = prepareData(schemaCtx, 42);
+ final NormalizedNode<?, ?> data = prepareData(schemaCtx, Uint16.valueOf(42));
final Entry<InstanceIdentifier<?>, DataObject> fromNormalizedNode = fromNormalizedNode(data, schemaCtx);
final DataObject value = fromNormalizedNode.getValue();
final Object id = declaredField.get(invoked);
final Field val = id.getClass().getDeclaredField("_value");
val.setAccessible(true);
- assertEquals(42, val.get(id));
+ assertEquals(Uint16.valueOf(42), val.get(id));
}
/**
private static final NodeIdentifier LEAF_ARG = new NodeIdentifier(QName.create(Cont.QNAME, "caching"));
private static final InstanceIdentifier<Cont> CONT_PATH = InstanceIdentifier.create(Cont.class);
- // Note: '400' is assumed to not be interned by the JVM here
- private static final Cont CONT_DATA = new ContBuilder().setCaching(new MyType(400)).setNonCaching("test").build();
- private static final Cont CONT2_DATA = new ContBuilder().setCaching(new MyType(400)).setNonCaching("test2").build();
+ private static final Cont CONT_DATA = new ContBuilder().setCaching(new MyType(dataValue())).setNonCaching("test")
+ .build();
+ private static final Cont CONT2_DATA = new ContBuilder().setCaching(new MyType(dataValue())).setNonCaching("test2")
+ .build();
private BindingDataObjectCodecTreeNode<Top> topNode;
private BindingDataObjectCodecTreeNode<Cont> contNode;
+ private static String dataValue() {
+ // We are battling interning here
+ return new StringBuilder("foo").toString();
+ }
+
@Override
@Before
public void before() {
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
NodeIdentifier.create(OspfStatLsdbBrief.QNAME),
NodeIdentifierWithPredicates.of(OspfStatLsdbBrief.QNAME, ImmutableMap.of(
QName.create(OspfStatLsdbBrief.QNAME, "AreaIndex"), 1,
- QName.create(OspfStatLsdbBrief.QNAME, "LsaType"), (short) 2,
+ QName.create(OspfStatLsdbBrief.QNAME, "LsaType"), Uint8.valueOf(2),
QName.create(OspfStatLsdbBrief.QNAME, "LsId"), 3,
QName.create(OspfStatLsdbBrief.QNAME, "AdvRtr"), "foo"))));
assertTrue(result instanceof KeyedInstanceIdentifier);
final Identifier<?> key = ((KeyedInstanceIdentifier<?, ?>) result).getKey();
- assertEquals(new OspfStatLsdbBriefKey("foo", 1, 3, (short)2), key);
+ assertEquals(new OspfStatLsdbBriefKey("foo", 1, 3, Uint8.valueOf(2)), key);
}
}
import org.opendaylight.yang.gen.v1.bug8449.rev170516.ContInt32Builder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
assertNotNull(fromYangInstanceIdentifier);
final InstanceIdentifier<ContInt32> BA_II_CONT = InstanceIdentifier.builder(ContInt32.class).build();
- final RefUnionInt32 refVal = new RefUnionInt32(5L);
+ final RefUnionInt32 refVal = new RefUnionInt32(Uint32.valueOf(5));
final ContInt32 data = new ContInt32Builder().setRefUnionInt32(refVal).build();
final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> normalizedNode =
this.registry.toNormalizedNode(BA_II_CONT, data);
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
public void bug6112Test() {
DataObject unionNodeObj = createValueNode("1");
UnionType unionTypeObj = ((UnionNode) unionNodeObj).getValue();
- assertEquals(Short.valueOf((short)1), unionTypeObj.getUint8());
+ assertEquals(Uint8.valueOf(1), unionTypeObj.getUint8());
assertEquals(null, unionTypeObj.getIdentityref());
}
}
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import java.math.BigDecimal;
-import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
} else if (base instanceof StringTypeDefinition) {
result = "\"" + defaultValue + "\"";
} else if (BaseTypes.isUint8(base)) {
- result = typeToValueOfDef(Short.class, defaultValue);
+ result = typeToValueOfDef(Uint8.class, defaultValue);
} else if (BaseTypes.isUint16(base)) {
- result = typeToValueOfDef(Integer.class, defaultValue);
+ result = typeToValueOfDef(Uint16.class, defaultValue);
} else if (BaseTypes.isUint32(base)) {
- result = typeToValueOfDef(Long.class, defaultValue);
+ result = typeToValueOfDef(Uint32.class, defaultValue);
} else if (BaseTypes.isUint64(base)) {
- switch (defaultValue) {
- case "0":
- result = "java.math.BigInteger.ZERO";
- break;
- case "1":
- result = "java.math.BigInteger.ONE";
- break;
- case "10":
- result = "java.math.BigInteger.TEN";
- break;
- default:
- result = typeToDef(BigInteger.class, defaultValue);
- }
+ result = typeToValueOfDef(Uint64.class, defaultValue);
} else if (base instanceof UnionTypeDefinition) {
result = unionToDef(node);
} else {
import com.google.common.collect.ImmutableMap;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.math.BigDecimal;
-import java.math.BigInteger;
import org.opendaylight.mdsal.binding.generator.spi.TypeProvider;
import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
import org.opendaylight.mdsal.binding.model.api.Restrictions;
import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
/**
* <code>Type</code> representation of <code>uint8</code> YANG type.
*/
- public static final Type UINT8_TYPE = Types.typeForClass(Short.class, singleRangeRestrictions((short)0,
- (short)255));
+ public static final Type UINT8_TYPE = Types.typeForClass(Uint8.class);
/**
* <code>Type</code> representation of <code>uint16</code> YANG type.
*/
- public static final Type UINT16_TYPE = Types.typeForClass(Integer.class, singleRangeRestrictions(0, 65535));
+ public static final Type UINT16_TYPE = Types.typeForClass(Uint16.class);
/**
* <code>Type</code> representation of <code>uint32</code> YANG type.
*/
- public static final Type UINT32_TYPE = Types.typeForClass(Long.class, singleRangeRestrictions(0L, 4294967295L));
+ public static final Type UINT32_TYPE = Types.typeForClass(Uint32.class);
/**
* <code>Type</code> representation of <code>uint64</code> YANG type.
*/
- public static final Type UINT64_TYPE = Types.typeForClass(BigInteger.class,
- singleRangeRestrictions(BigInteger.ZERO, new BigInteger("18446744073709551615")));
+ public static final Type UINT64_TYPE = Types.typeForClass(Uint64.class);
public static final Type UNION_TYPE = new UnionType();
case "string":
return Types.typeForClass(String.class, restrictions);
case "uint8":
- return Types.typeForClass(Short.class, restrictions);
+ return Types.typeForClass(Uint8.class, restrictions);
case "uint16":
- return Types.typeForClass(Integer.class, restrictions);
+ return Types.typeForClass(Uint16.class, restrictions);
case "uint32":
- return Types.typeForClass(Long.class, restrictions);
+ return Types.typeForClass(Uint32.class, restrictions);
case "uint64":
- return Types.typeForClass(BigInteger.class, restrictions);
+ return Types.typeForClass(Uint64.class, restrictions);
case "union" :
return UNION_TYPE;
default:
}
};
- private static <T extends Number & Comparable<T>> Restrictions singleRangeRestrictions(final T min, final T max) {
- return Types.getDefaultRestrictions(min, max);
- }
-
// FIXME: 5.0.0: remove this class
@Deprecated
public static final class UnionType implements Type {
lf1Leaf.getIdentifier().immediatelyEnclosingClass().get().toString());
assertEquals("Lf generated TO has incorrect number of properties", 4, lf1Leaf.getProperties().size());
- containsAttributes(lf1Leaf, true, true, true, new NameTypePattern("uint32", "Long"));
+ containsAttributes(lf1Leaf, true, true, true, new NameTypePattern("uint32", "Uint32"));
containsAttributes(lf1Leaf, true, true, true, new NameTypePattern("int8", "Byte"));
containsAttributes(lf1Leaf, true, true, true, new NameTypePattern("string", "String"));
containsAttributes(lf1Leaf, true, false, true, new NameTypePattern("lf$2", "Lf$2"));
assertEquals("Lf generated TO has incorrect number of properties", 2, lf2Leaf.getProperties().size());
containsAttributes(lf2Leaf, true, true, true, new NameTypePattern("string", "String"));
- containsAttributes(lf2Leaf, true, true, true, new NameTypePattern("uint64", "BigInteger"));
+ containsAttributes(lf2Leaf, true, true, true, new NameTypePattern("uint64", "Uint64"));
}
@Test
assertEquals("TypeUnion1 generated TO has incorrect number of properties", 4,
typeUnion1.getProperties().size());
- containsAttributes(typeUnion1, true, true, true, new NameTypePattern("uint32", "Long"));
+ containsAttributes(typeUnion1, true, true, true, new NameTypePattern("uint32", "Uint32"));
containsAttributes(typeUnion1, true, true, true, new NameTypePattern("int8", "Byte"));
containsAttributes(typeUnion1, true, true, true, new NameTypePattern("string", "String"));
containsAttributes(typeUnion1, true, false, true, new NameTypePattern("typeUnion$2", "TypeUnion$2"));
assertEquals("TypeUnion2 generated TO has incorrect number of properties", 2,
typeUnion2.getProperties().size());
containsAttributes(typeUnion2, true, true, true, new NameTypePattern("string", "String"));
- containsAttributes(typeUnion2, true, true, true, new NameTypePattern("uint64", "BigInteger"));
+ containsAttributes(typeUnion2, true, true, true, new NameTypePattern("uint64", "Uint64"));
}
assertEquals("uint32 property has incorrect type", "Integer", uint32Property.getReturnType().getName());
assertEquals("string property has incorrect type", "String", stringProperty.getReturnType().getName());
- assertEquals("uint8 property has incorrect type", "Short", uint8Property.getReturnType().getName());
+ assertEquals("uint8 property has incorrect type", "Uint8", uint8Property.getReturnType().getName());
}
genType = checkGeneratedType(genTypes, "AnonymousLock", pcgPref
+ ".netconf.state.datastores.datastore.locks.lock.type"); // choice
- containsMethods(genType, new NameTypePattern("getLockTime", "Long"));
+ containsMethods(genType, new NameTypePattern("getLockTime", "Uint32"));
containsInterface("LockType", genType);
genType = checkGeneratedType(genTypes, "LeafAugCase", pcgPref
}
} else if (unionLeafProperty.getName().equals("uint8")) {
uint8UnionPropertyFound = true;
- if (unionLeafPropertyType.equals("Short")) {
+ if (unionLeafPropertyType.equals("Uint8")) {
uint8UnionPropertyTypeOK = true;
}
}
}
assertEquals(1, getFooMethodCounter);
- assertEquals("Short", getFooMethodReturnTypeName);
+ assertEquals("Uint8", getFooMethodReturnTypeName);
assertEquals(1, getBarMethodCounter);
assertEquals("String", getBarMethodReturnTypeName);
}
assertEquals(1, getFooMethodCounter);
- assertEquals("Short", getFooMethodReturnTypeName);
+ assertEquals("Uint8", getFooMethodReturnTypeName);
assertEquals(1, getBarMethodCounter);
assertEquals("List", getBarMethodReturnTypeName);
final QName leafNode1 = QName.create(module.getQNameModule(), "leaf-uint8");
LeafSchemaNode leaf = (LeafSchemaNode) module.findDataChildByName(leafNode1).get();
String actual = provider.getTypeDefaultConstruction(leaf);
- assertEquals("java.lang.Short.valueOf(\"11\")", actual);
+ assertEquals("org.opendaylight.yangtools.yang.common.Uint8.valueOf(\"11\")", actual);
final QName leafNode2 = QName.create(module.getQNameModule(), "ext-uint8");
leaf = (LeafSchemaNode) module.findDataChildByName(leafNode2).get();
actual = provider.getTypeDefaultConstruction(leaf);
- assertEquals("new " + PKG + "MyUint8(java.lang.Short.valueOf(\"11\"))", actual);
+ assertEquals("new " + PKG + "MyUint8(org.opendaylight.yangtools.yang.common.Uint8.valueOf(\"11\"))", actual);
}
@Test
final QName leafNode1 = QName.create(module.getQNameModule(), "leaf-uint16");
LeafSchemaNode leaf = (LeafSchemaNode) module.findDataChildByName(leafNode1).get();
String actual = provider.getTypeDefaultConstruction(leaf);
- assertEquals("java.lang.Integer.valueOf(\"111\")", actual);
+ assertEquals("org.opendaylight.yangtools.yang.common.Uint16.valueOf(\"111\")", actual);
final QName leafNode2 = QName.create(module.getQNameModule(), "ext-uint16");
leaf = (LeafSchemaNode) module.findDataChildByName(leafNode2).get();
actual = provider.getTypeDefaultConstruction(leaf);
- assertEquals("new " + PKG + "MyUint16(java.lang.Integer.valueOf(\"111\"))", actual);
+ assertEquals("new " + PKG + "MyUint16(org.opendaylight.yangtools.yang.common.Uint16.valueOf(\"111\"))", actual);
}
@Test
final QName leafNode1 = QName.create(module.getQNameModule(), "leaf-uint32");
LeafSchemaNode leaf = (LeafSchemaNode) module.findDataChildByName(leafNode1).get();
String actual = provider.getTypeDefaultConstruction(leaf);
- assertEquals("java.lang.Long.valueOf(\"1111\")", actual);
+ assertEquals("org.opendaylight.yangtools.yang.common.Uint32.valueOf(\"1111\")", actual);
final QName leafNode2 = QName.create(module.getQNameModule(), "ext-uint32");
leaf = (LeafSchemaNode) module.findDataChildByName(leafNode2).get();
actual = provider.getTypeDefaultConstruction(leaf);
- assertEquals("new " + PKG + "MyUint32(java.lang.Long.valueOf(\"1111\"))", actual);
+ assertEquals("new " + PKG + "MyUint32(org.opendaylight.yangtools.yang.common.Uint32.valueOf(\"1111\"))",
+ actual);
}
@Test
final QName leafNode1 = QName.create(module.getQNameModule(), "leaf-uint64");
LeafSchemaNode leaf = (LeafSchemaNode) module.findDataChildByName(leafNode1).get();
String actual = provider.getTypeDefaultConstruction(leaf);
- assertEquals("new java.math.BigInteger(\"11111\")", actual);
+ assertEquals("org.opendaylight.yangtools.yang.common.Uint64.valueOf(\"11111\")", actual);
final QName leafNode2 = QName.create(module.getQNameModule(), "ext-uint64");
leaf = (LeafSchemaNode) module.findDataChildByName(leafNode2).get();
actual = provider.getTypeDefaultConstruction(leaf);
- assertEquals("new " + PKG + "MyUint64(new java.math.BigInteger(\"11111\"))", actual);
+ assertEquals("new " + PKG + "MyUint64(org.opendaylight.yangtools.yang.common.Uint64.valueOf(\"11111\"))",
+ actual);
}
@Test
containsMethods(groupingContainerTest.getMethodDefinitions(), new NameTypePattern(
"getLeafGroupingContainerTest1", "String"), new NameTypePattern("getLeafGroupingContainerTest2",
- "Short"));
+ "Uint8"));
containsMethods(containerTest.getMethodDefinitions(), new NameTypePattern("getContainerLeafTest", "String"));
}
"getListGroupingListTest", "List<ListGroupingListTest>"));
containsMethods(listTest.getMethodDefinitions(), new NameTypePattern("getListLeafTest", "String"));
containsMethods(containerGroupingListTest.getMethodDefinitions(), new NameTypePattern(
- "getLeafContainerGroupingListTest", "Short"));
+ "getLeafContainerGroupingListTest", "Uint8"));
containsMethods(listGroupingListTest.getMethodDefinitions(), new NameTypePattern("getLeafListGroupingListTest",
"Integer"));
}
.size());
containsMethods(groupingModulTest.getMethodDefinitions(), new NameTypePattern("getLeafGroupingModulTest",
- "String"), new NameTypePattern("getLeafGroupingModulTest2", "Short"));
+ "String"), new NameTypePattern("getLeafGroupingModulTest2", "Uint8"));
}
@Test
containsMethods(groupingRpcInputTest.getMethodDefinitions(), new NameTypePattern(
"getContainerGroupingRpcInputTest", "ContainerGroupingRpcInputTest"), new NameTypePattern(
- "getLeaflistGroupingRpcInputTest", "List<Short>"));
+ "getLeaflistGroupingRpcInputTest", "List<Uint8>"));
containsMethods(groupingRpcOutputTest.getMethodDefinitions(), new NameTypePattern(
"getLeafGroupingRpcOutputTest", "Byte"));
containsMethods(containerGroupingRpcInputTest.getMethodDefinitions(), new NameTypePattern(
"getContainerGroupingNotificationTest", "ContainerGroupingNotificationTest"), new NameTypePattern(
"getLeaffllistGroupingNotificationTest", "List<String>"));
containsMethods(containerGroupingNotificationTest.getMethodDefinitions(), new NameTypePattern(
- "getLeafContainerGroupingNotificationTest", "Long"));
+ "getLeafContainerGroupingNotificationTest", "Uint32"));
}
}
import static org.junit.Assert.assertTrue;
import java.math.BigDecimal;
-import java.math.BigInteger;
import java.util.Set;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.mdsal.binding.model.api.Type;
import org.opendaylight.mdsal.binding.model.util.BindingGeneratorUtil;
import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
javaType = typeProvider.javaTypeForSchemaDefinitionType(uint8, uint8);
assertNotNull(javaType);
- assertEquals(Short.class.getCanonicalName(), javaType.getFullyQualifiedName());
+ assertEquals(Uint8.class.getCanonicalName(), javaType.getFullyQualifiedName());
javaType = typeProvider.javaTypeForSchemaDefinitionType(uint16, uint16);
assertNotNull(javaType);
- assertEquals(Integer.class.getCanonicalName(), javaType.getFullyQualifiedName());
+ assertEquals(Uint16.class.getCanonicalName(), javaType.getFullyQualifiedName());
javaType = typeProvider.javaTypeForSchemaDefinitionType(uint32, uint32);
assertNotNull(javaType);
- assertEquals(Long.class.getCanonicalName(), javaType.getFullyQualifiedName());
+ assertEquals(Uint32.class.getCanonicalName(), javaType.getFullyQualifiedName());
javaType = typeProvider.javaTypeForSchemaDefinitionType(uint64, uint64);
assertNotNull(javaType);
- assertEquals(BigInteger.class.getCanonicalName(), javaType.getFullyQualifiedName());
+ assertEquals(Uint64.class.getCanonicalName(), javaType.getFullyQualifiedName());
javaType = typeProvider.javaTypeForSchemaDefinitionType(union, union);
assertNotNull(javaType);
javaType = typeProvider.javaTypeForSchemaDefinitionType(uint8, uint8,
BindingGeneratorUtil.getRestrictions(uint8));
assertNotNull(javaType);
- assertEquals(Short.class.getCanonicalName(), javaType.getFullyQualifiedName());
+ assertEquals(Uint8.class.getCanonicalName(), javaType.getFullyQualifiedName());
javaType = typeProvider.javaTypeForSchemaDefinitionType(uint16, uint16,
BindingGeneratorUtil.getRestrictions(uint16));
assertNotNull(javaType);
- assertEquals(Integer.class.getCanonicalName(), javaType.getFullyQualifiedName());
+ assertEquals(Uint16.class.getCanonicalName(), javaType.getFullyQualifiedName());
javaType = typeProvider.javaTypeForSchemaDefinitionType(uint32, uint32,
BindingGeneratorUtil.getRestrictions(uint32));
assertNotNull(javaType);
- assertEquals(Long.class.getCanonicalName(), javaType.getFullyQualifiedName());
+ assertEquals(Uint32.class.getCanonicalName(), javaType.getFullyQualifiedName());
javaType = typeProvider.javaTypeForSchemaDefinitionType(uint64, uint64,
BindingGeneratorUtil.getRestrictions(uint64));
assertNotNull(javaType);
- assertEquals(BigInteger.class.getCanonicalName(), javaType.getFullyQualifiedName());
+ assertEquals(Uint64.class.getCanonicalName(), javaType.getFullyQualifiedName());
javaType = typeProvider.javaTypeForSchemaDefinitionType(union, union,
BindingGeneratorUtil.getRestrictions(union));
assertNotNull(result);
assertTrue(!result.isEmpty());
assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914."
- + "YangUint8(java.lang.Short.valueOf(\"128\"))", result);
+ + "YangUint8(org.opendaylight.yangtools.yang.common.Uint8.valueOf(\"128\"))", result);
leaf = provideLeafForGetDefaultConstructionTestCase("yang-uint16");
result = provider.getTypeDefaultConstruction(leaf, "1048576");
assertNotNull(result);
assertTrue(!result.isEmpty());
assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914."
- + "YangUint16(java.lang.Integer.valueOf(\"1048576\"))", result);
+ + "YangUint16(org.opendaylight.yangtools.yang.common.Uint16.valueOf(\"1048576\"))", result);
leaf = provideLeafForGetDefaultConstructionTestCase("yang-uint32");
result = provider.getTypeDefaultConstruction(leaf, "1099511627776");
assertNotNull(result);
assertTrue(!result.isEmpty());
assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914."
- + "YangUint32(java.lang.Long.valueOf(\"1099511627776\"))", result);
+ + "YangUint32(org.opendaylight.yangtools.yang.common.Uint32.valueOf(\"1099511627776\"))", result);
leaf = provideLeafForGetDefaultConstructionTestCase("yang-uint64");
result = provider.getTypeDefaultConstruction(leaf, "1208925819614629174706176");
assertNotNull(result);
assertTrue(!result.isEmpty());
assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914."
- + "YangUint64(new java.math.BigInteger(\"1208925819614629174706176\"))", result);
+ + "YangUint64(org.opendaylight.yangtools.yang.common.Uint64.valueOf(\"1208925819614629174706176\"))",
+ result);
//FIXME: Is this correct scenario and correct result?
leaf = provideLeafForGetDefaultConstructionTestCase("complex-union");
return minValue.compareTo(minToEnforce) < 0;
}
- private Collection<String> createExpressions(final RangeConstraint<?> constraint) {
+ private Collection<String> createExpressions(final RangeConstraint<?> constraint,
+ final Function<Class<?>, String> classImporter) {
final Set<? extends Range<? extends Number>> constraints = constraint.getAllowedRanges().asRanges();
final Collection<String> ret = new ArrayList<>(constraints.size());
final StringBuilder sb = new StringBuilder();
if (needMin) {
- sb.append("value >= ").append(format(min));
+ appendMinCheck(sb, min, classImporter);
}
if (needMax) {
if (needMin) {
sb.append(" && ");
}
- sb.append("value <= ").append(format(max));
+ appendMaxCheck(sb, max, classImporter);
}
ret.add(sb.toString());
return ret;
}
+ void appendMaxCheck(final StringBuilder sb, final T max, final Function<Class<?>, String> classImporter) {
+ sb.append("value <= ").append(format(max));
+ }
+
+ void appendMinCheck(final StringBuilder sb, final T min, final Function<Class<?>, String> classImporter) {
+ sb.append("value >= ").append(format(min));
+ }
+
+ String codeHelpersThrow() {
+ return "throwInvalidRange";
+ }
+
private String createRangeString(final RangeConstraint<?> constraint) {
final Set<? extends Range<? extends Number>> constraints = constraint.getAllowedRanges().asRanges();
final List<Range<T>> ranges = new ArrayList<>(constraints.size());
protected final String generateRangeCheckerImplementation(final String checkerName,
final RangeConstraint<?> constraints, final Function<Class<?>, String> classImporter) {
final StringBuilder sb = new StringBuilder();
- final Collection<String> expressions = createExpressions(constraints);
+ final Collection<String> expressions = createExpressions(constraints, classImporter);
sb.append("private static void ").append(checkerName).append("(final ").append(primitiveName)
.append(" value) {\n");
sb.append(" }\n");
}
- sb.append(" ").append(classImporter.apply(CodeHelpers.class)).append(".throwInvalidRange(\"")
- .append(createRangeString(constraints)).append("\", value);\n");
+ sb.append(" ").append(classImporter.apply(CodeHelpers.class)).append('.').append(codeHelpersThrow())
+ .append("(\"").append(createRangeString(constraints)).append("\", value);\n");
}
return sb.append("}\n").toString();
addGenerator(b, new LongRangeGenerator());
addGenerator(b, new BigDecimalRangeGenerator());
addGenerator(b, new BigIntegerRangeGenerator());
+ addGenerator(b, new Uint8RangeGenerator());
+ addGenerator(b, new Uint16RangeGenerator());
+ addGenerator(b, new Uint32RangeGenerator());
+ addGenerator(b, new Uint64RangeGenerator());
GENERATORS = b.build();
}
- private final Class<T> type;
+ private final @NonNull Class<T> type;
protected AbstractRangeGenerator(final Class<T> typeClass) {
this.type = requireNonNull(typeClass);
protected abstract @NonNull String generateRangeCheckerImplementation(@NonNull String checkerName,
@NonNull RangeConstraint<?> constraints, Function<Class<?>, String> classImporter);
- private static String rangeCheckerName(final String member) {
+ private static @NonNull String rangeCheckerName(final String member) {
return "check" + member + "Range";
}
}
String generateRangeCheckerCall(final @NonNull String member, final @NonNull String valueReference) {
- return rangeCheckerName(member) + '(' + valueReference + ");\n";
+ return rangeCheckerName(member) + '(' + valueReference + primitiveRef() + ");\n";
+ }
+
+ String primitiveRef() {
+ return "";
}
}
--- /dev/null
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.java.api.generator;
+
+import org.eclipse.jdt.annotation.NonNull;
+
+abstract class AbstractUnsignedRangeGenerator<T extends Number & Comparable<T>>
+ extends AbstractPrimitiveRangeGenerator<T> {
+ private final @NonNull String primitiveRef;
+
+ AbstractUnsignedRangeGenerator(final Class<T> typeClass, final String primitiveName, final T minValue,
+ final T maxValue) {
+ super(typeClass, primitiveName, minValue, maxValue);
+ primitiveRef = "." + primitiveName + "Value()";
+ }
+
+ @Override
+ final String primitiveRef() {
+ return primitiveRef;
+ }
+}
import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTATION_FIELD
import com.google.common.collect.ImmutableList
+import com.google.common.collect.ImmutableMap
+import java.math.BigInteger
import java.util.ArrayList
import java.util.Collection
import java.util.HashMap
import org.opendaylight.yangtools.yang.binding.AugmentationHolder
import org.opendaylight.yangtools.yang.binding.CodeHelpers
import org.opendaylight.yangtools.yang.binding.DataObject
+import org.opendaylight.yangtools.yang.common.Uint8
+import org.opendaylight.yangtools.yang.common.Uint16
+import org.opendaylight.yangtools.yang.common.Uint64
+import org.opendaylight.yangtools.yang.common.Uint32
/**
* Template for generating JAVA builder classes.
*/
public static val BUILDER = "Builder";
+ static val UINT_TYPES = ImmutableMap.of(
+ Types.typeForClass(Uint8), Types.typeForClass(Short),
+ Types.typeForClass(Uint16), Types.typeForClass(Integer),
+ Types.typeForClass(Uint32), Types.typeForClass(Long),
+ Types.typeForClass(Uint64), Types.typeForClass(BigInteger)
+ );
+
/**
* Constructs new instance of this class.
* @throws IllegalArgumentException if <code>genType</code> equals <code>null</code>
«generateCheckers(field, restrictions, actualType)»
«ENDIF»
- public «type.getName» set«field.getName.toFirstUpper»(final «field.returnType.importedName» value) {
+ «val setterName = "set" + field.getName.toFirstUpper»
+ public «type.getName» «setterName»(final «field.returnType.importedName» value) {
«IF restrictions !== null»
if (value != null) {
«checkArgument(field, restrictions, actualType, "value")»
this.«field.fieldName.toString» = value;
return this;
}
+ «val uintType = UINT_TYPES.get(field.returnType)»
+ «IF uintType !== null»
+
+ /**
+ * Utility migration setter.
+ *
+ * @deprecated Use {#link «setterName»(«field.returnType.importedName»)} instead.
+ */
+ @Deprecated(forRemoval = true)
+ public «type.getName» «setterName»(final «uintType.importedName» value) {
+ return «setterName»(«CodeHelpers.importedName».compatUint(value));
+ }
+ «ENDIF»
'''
private def Type getActualType(ParameterizedType ptype) {
import org.opendaylight.mdsal.binding.model.util.TypeConstants
import org.opendaylight.yangtools.yang.binding.CodeHelpers
import org.opendaylight.yangtools.yang.common.Empty
+import org.opendaylight.yangtools.yang.common.Uint16
+import org.opendaylight.yangtools.yang.common.Uint32
+import org.opendaylight.yangtools.yang.common.Uint64
+import org.opendaylight.yangtools.yang.common.Uint8
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition
/**
return new «genTO.name»(«Integer.importedName».valueOf(defaultValue));
«ELSEIF "java.lang.Long".equals(prop.returnType.fullyQualifiedName)»
return new «genTO.name»(«Long.importedName».valueOf(defaultValue));
+ «ELSEIF "org.opendaylight.yangtools.yang.common.Uint8".equals(prop.returnType.fullyQualifiedName)»
+ return new «genTO.name»(«Uint8.importedName».valueOf(defaultValue));
+ «ELSEIF "org.opendaylight.yangtools.yang.common.Uint16".equals(prop.returnType.fullyQualifiedName)»
+ return new «genTO.name»(«Uint16.importedName».valueOf(defaultValue));
+ «ELSEIF "org.opendaylight.yangtools.yang.common.Uint32".equals(prop.returnType.fullyQualifiedName)»
+ return new «genTO.name»(«Uint32.importedName».valueOf(defaultValue));
+ «ELSEIF "org.opendaylight.yangtools.yang.common.Uint64".equals(prop.returnType.fullyQualifiedName)»
+ return new «genTO.name»(«Uint64.importedName».valueOf(defaultValue));
«ELSE»
return new «genTO.name»(new «prop.returnType.importedName»(defaultValue));
«ENDIF»
--- /dev/null
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.java.api.generator;
+
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint8;
+
+final class Uint16RangeGenerator extends AbstractUnsignedRangeGenerator<Uint16> {
+ Uint16RangeGenerator() {
+ super(Uint16.class, int.class.getName(), Uint16.ZERO, Uint16.MAX_VALUE);
+ }
+
+ @Override
+ @Deprecated
+ protected Uint16 convert(final Number value) {
+ if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Uint8) {
+ return Uint16.valueOf(value.intValue());
+ }
+ return Uint16.valueOf(value.toString());
+ }
+
+ @Override
+ protected String format(final Uint16 value) {
+ return value.toCanonicalString();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.java.api.generator;
+
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint8;
+
+final class Uint32RangeGenerator extends AbstractUnsignedRangeGenerator<Uint32> {
+ Uint32RangeGenerator() {
+ super(Uint32.class, long.class.getName(), Uint32.ZERO, Uint32.MAX_VALUE);
+ }
+
+ @Override
+ @Deprecated
+ protected Uint32 convert(final Number value) {
+ if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long
+ || value instanceof Uint8 || value instanceof Uint16) {
+ return Uint32.valueOf(value.longValue());
+ }
+ return Uint32.valueOf(value.toString());
+ }
+
+ @Override
+ protected String format(final Uint32 value) {
+ return value.toCanonicalString() + 'L';
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.java.api.generator;
+
+import java.util.function.Function;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
+
+final class Uint64RangeGenerator extends AbstractUnsignedRangeGenerator<Uint64> {
+ Uint64RangeGenerator() {
+ super(Uint64.class, long.class.getName(), Uint64.ZERO, Uint64.MAX_VALUE);
+ }
+
+ @Override
+ @Deprecated
+ protected Uint64 convert(final Number value) {
+ if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long
+ || value instanceof Uint8 || value instanceof Uint16 || value instanceof Uint32) {
+ return Uint64.valueOf(value.longValue());
+ }
+ return Uint64.valueOf(value.toString());
+ }
+
+ @Override
+ protected String format(final Uint64 value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ String codeHelpersThrow() {
+ return "throwInvalidRangeUnsigned";
+ }
+
+ @Override
+ void appendMaxCheck(final StringBuilder sb, final Uint64 max, final Function<Class<?>, String> classImporter) {
+ appendCompare(sb, classImporter, max, "<=");
+ }
+
+ @Override
+ void appendMinCheck(final StringBuilder sb, final Uint64 min, final Function<Class<?>, String> classImporter) {
+ appendCompare(sb, classImporter, min, ">=");
+ }
+
+ private static StringBuilder appendCompare(final StringBuilder sb, final Function<Class<?>, String> classImporter,
+ final Uint64 val, final String operator) {
+ return sb.append(classImporter.apply(Long.class)).append(".compareUnsigned(value, ").append(val.longValue())
+ .append("L) ").append(operator).append(" 0");
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.java.api.generator;
+
+import org.opendaylight.yangtools.yang.common.Uint8;
+
+final class Uint8RangeGenerator extends AbstractUnsignedRangeGenerator<Uint8> {
+ Uint8RangeGenerator() {
+ super(Uint8.class, short.class.getName(), Uint8.ZERO, Uint8.MAX_VALUE);
+ }
+
+ @Override
+ @Deprecated
+ protected Uint8 convert(final Number value) {
+ if (value instanceof Byte) {
+ return Uint8.valueOf(value.byteValue());
+ }
+ return Uint8.valueOf(value.toString());
+ }
+
+ @Override
+ protected String format(final Uint8 value) {
+ return "(short)" + value.toCanonicalString();
+ }
+}
return new «String.importedName»(«field»);
«ELSEIF propRet.fullyQualifiedName.startsWith("java.lang") || propRet instanceof Enumeration
|| propRet.fullyQualifiedName.startsWith("java.math")»
- ««« type int*, uint, decimal64 or enumeration*
+ ««« type int*, decimal64 or enumeration*
return «field».toString();
+ «ELSEIF "org.opendaylight.yangtools.yang.common".equals(propRet.packageName)
+ && propRet.name.startsWith("Uint")»
+ ««« type uint*
+ return «field».toCanonicalString();
«ELSEIF propRet instanceof GeneratedTransferObject && (propRet as GeneratedTransferObject).unionType»
««« union type
return «field».stringValue();
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.WildcardType;
import java.math.BigDecimal;
-import java.math.BigInteger;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import org.opendaylight.yangtools.yang.binding.ChildOf;
import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
/**
* Test correct code generation.
CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getId64");
CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getIdLeafref");
CompilationTestUtils.assertContainsMethod(nodesClass, String.class, "getIdString");
- CompilationTestUtils.assertContainsMethod(nodesClass, Short.class, "getIdU8");
- CompilationTestUtils.assertContainsMethod(nodesClass, Integer.class, "getIdU16");
- CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getIdU32");
- CompilationTestUtils.assertContainsMethod(nodesClass, BigInteger.class, "getIdU64");
+ CompilationTestUtils.assertContainsMethod(nodesClass, Uint8.class, "getIdU8");
+ CompilationTestUtils.assertContainsMethod(nodesClass, Uint16.class, "getIdU16");
+ CompilationTestUtils.assertContainsMethod(nodesClass, Uint32.class, "getIdU32");
+ CompilationTestUtils.assertContainsMethod(nodesClass, Uint64.class, "getIdU64");
CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdUnion", "getIdUnion", loader);
final Object builderObj = builderClass.getDeclaredConstructor().newInstance();
package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.bug._6006.rev160607;
+import org.opendaylight.yangtools.yang.common.Uint8;
+
/**
* The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
* In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
}
try {
- return new UnionType(Short.valueOf(defaultValue));
+ return new UnionType(Uint8.valueOf(defaultValue));
} catch (NumberFormatException e) {
/* do nothing */
}
revision 2019-02-01;
typedef my-type {
- type uint16 {
- range "1..4094";
+ type string {
+ length 2..5;
}
}
- container cont{
+ container cont {
leaf caching {
type my-type;
}
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.VerifyException;
import com.google.common.collect.ImmutableList;
+import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
/**
* Helper methods for generated binding code. This class concentrates useful primitives generated code may call
throwInvalidRange(Arrays.toString(expected), actual);
}
+ /**
+ * Throw an IllegalArgument exception describing a range violation of an Uint64 type.
+ *
+ * @param expected String describing expected ranges
+ * @param actual Actual observed value
+ * @throws IllegalArgumentException always
+ */
+ public static void throwInvalidRangeUnsigned(final String expected, final long actual) {
+ throw new IllegalArgumentException("Invalid range: " + Long.toUnsignedString(actual) + ", expected: " + expected
+ + ".");
+ }
+
/**
* Check whether specified List is null and if so return an immutable list instead. This method supports
* non-null default getter methods.
return wrapHashCode(Arrays.hashCode(obj));
}
+ /**
+ * Compatibility utility for converting a legacy {@link Short} {@code uint8} value to its {@link Uint8}
+ * counterpart.
+ *
+ * @param value Legacy value
+ * @return Converted value
+ * @throws IllegalArgumentException if the value does not fit an Uint8
+ * @deprecated This method is provided for migration purposes only, do not use it outside of deprecated
+ * compatibility methods.
+ */
+ @Deprecated
+ public static @Nullable Uint8 compatUint(final @Nullable Short value) {
+ return value == null ? null : Uint8.valueOf(value.shortValue());
+ }
+
+ /**
+ * Compatibility utility for converting a legacy {@link Integer} {@code uint16} value to its {@link Uint16}
+ * counterpart.
+ *
+ * @param value Legacy value
+ * @return Converted value
+ * @throws IllegalArgumentException if the value does not fit an Uint16
+ * @deprecated This method is provided for migration purposes only, do not use it outside of deprecated
+ * compatibility methods.
+ */
+ @Deprecated
+ public static @Nullable Uint16 compatUint(final @Nullable Integer value) {
+ return value == null ? null : Uint16.valueOf(value.intValue());
+ }
+
+ /**
+ * Compatibility utility for converting a legacy {@link Long} {@code uint32} value to its {@link Uint32}
+ * counterpart.
+ *
+ * @param value Legacy value
+ * @return Converted value
+ * @throws IllegalArgumentException if the value does not fit an Uint32
+ * @deprecated This method is provided for migration purposes only, do not use it outside of deprecated
+ * compatibility methods.
+ */
+ @Deprecated
+ public static @Nullable Uint32 compatUint(final @Nullable Long value) {
+ return value == null ? null : Uint32.valueOf(value.longValue());
+ }
+
+ /**
+ * Compatibility utility for converting a legacy {@link BigInteger} {@code uint64} value to its {@link Uint64}
+ * counterpart.
+ *
+ * @param value Legacy value
+ * @return Converted value
+ * @throws IllegalArgumentException if the value does not fit an Uint64
+ * @deprecated This method is provided for migration purposes only, do not use it outside of deprecated
+ * compatibility methods.
+ */
+ @Deprecated
+ public static @Nullable Uint64 compatUint(final @Nullable BigInteger value) {
+ return value == null ? null : Uint64.valueOf(value);
+ }
+
/**
* The constant '31' is the result of folding this code:
* <pre>
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yangtools.util.ClassLoaderUtils;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
}
- return new MplsLabel(new MplsLabelGeneralUse(Long.valueOf(defaultValue)));
+ return new MplsLabel(new MplsLabelGeneralUse(Uint32.valueOf(defaultValue)));
}
static Optional<MplsLabel> loadClass(final ClassLoader loader, final String key) {
import java.util.Arrays;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.TimerValueMilliseconds.Enumeration;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* Builder for {@link TimerValueMilliseconds} instances.
public static TimerValueMilliseconds getDefaultInstance(final String defaultValue) {
return Enumeration.forName(defaultValue).map(ENUMERATED::get)
- .orElse(new TimerValueMilliseconds(Long.valueOf(defaultValue)));
+ .orElse(new TimerValueMilliseconds(Uint32.valueOf(defaultValue)));
}
public static TimerValueMilliseconds forEnumeration(final Enumeration enumeration) {
import java.util.Arrays;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.TimerValueSeconds16.Enumeration;
+import org.opendaylight.yangtools.yang.common.Uint16;
/**
* Builder for {@link TimerValueSeconds16} instances.
public static TimerValueSeconds16 getDefaultInstance(final String defaultValue) {
return Enumeration.forName(defaultValue).map(ENUMERATED::get)
- .orElse(new TimerValueSeconds16(Integer.valueOf(defaultValue)));
+ .orElse(new TimerValueSeconds16(Uint16.valueOf(defaultValue)));
}
public static TimerValueSeconds16 forEnumeration(final Enumeration enumeration) {
import java.util.Arrays;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.TimerValueSeconds32.Enumeration;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* Builder for {@link TimerValueSeconds32} instances.
public static TimerValueSeconds32 getDefaultInstance(final String defaultValue) {
return Enumeration.forName(defaultValue).map(ENUMERATED::get)
- .orElse(new TimerValueSeconds32(Long.valueOf(defaultValue)));
+ .orElse(new TimerValueSeconds32(Uint32.valueOf(defaultValue)));
}
public static TimerValueSeconds32 forEnumeration(final Enumeration enumeration) {
import java.util.Objects;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ethertypes.rev190304.Ethertype.Enumeration;
public final class EthertypeBuilder {
if (length > 0 && length < 6 && DIGITS.matchesAllOf(defaultValue)) {
final int value = Integer.parseInt(defaultValue);
if (value < 65536) {
- return new Ethertype(value);
+ return new Ethertype(Uint16.valueOf(value));
}
// Fall through and interpret as a string
private static int extractValue(final Ethertype type) {
final Enumeration known = type.getEnumeration();
- return known != null ? known.getIntValue() : verifyNotNull(type.getUint16());
+ return known != null ? known.getIntValue() : verifyNotNull(type.getUint16()).intValue();
}
}