*/
package org.opendaylight.mdsal.binding.dom.codec.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Map.Entry;
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.bug5446.rev151105.IpAddressBinary;
-import org.opendaylight.yang.gen.v1.bug5446.rev151105.IpAddressBinaryBuilder;
-import org.opendaylight.yang.gen.v1.bug5446.rev151105.Root;
-import org.opendaylight.yang.gen.v1.bug5446.rev151105.RootBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.union.rev150121.TopLevel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.union.rev150121.TopLevelBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.union.rev150121.Wrapper;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.union.rev150121.WrapperBuilder;
-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.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-
public class UnionTypeTest extends AbstractBindingCodecTest {
- private static final String TEST_STRING = "testtesttest";
- private static final QName WRAPPER_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:yangtools:test:union",
- "2015-01-21", "wrapper");
- private static final QName WRAP_LEAF_QNAME = QName.create(WRAPPER_QNAME, "wrap");
-
- @Test
- public void unionTest() {
- TopLevel topLevel = TopLevelBuilder.getDefaultInstance(TEST_STRING);
- Wrapper wrapper = new WrapperBuilder().setWrap(topLevel).build();
- NormalizedNode topLevelEntry = codecContext.toNormalizedNode(InstanceIdentifier.create(Wrapper.class),
- wrapper).getValue();
-
- ContainerNode containerNode = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new NodeIdentifier(WRAPPER_QNAME))
- .withChild(ImmutableNodes.leafNode(WRAP_LEAF_QNAME, TEST_STRING))
- .build();
- Assert.assertEquals(topLevelEntry, containerNode);
- }
-
- @Test
- public void bug5446Test() {
- IpAddressBinary ipAddress = IpAddressBinaryBuilder.getDefaultInstance("fwAAAQ==");
- Root root = new RootBuilder().setIpAddress(ipAddress).build();
- NormalizedNode rootNode = codecContext.toNormalizedNode(InstanceIdentifier.create(Root.class), root)
- .getValue();
-
- Entry<InstanceIdentifier<?>, DataObject> rootEntry = codecContext.fromNormalizedNode(
- YangInstanceIdentifier.of(rootNode.getIdentifier().getNodeType()), rootNode);
-
- DataObject rootObj = rootEntry.getValue();
- assertTrue(rootObj instanceof Root);
- IpAddressBinary desIpAddress = ((Root) rootObj).getIpAddress();
- assertEquals(ipAddress, desIpAddress);
- }
+ // FIXME: MDSAL-741: re-enable this test
+ // private static final String TEST_STRING = "testtesttest";
+ // private static final QName WRAPPER_QNAME = QName.create(
+ // "urn:opendaylight:params:xml:ns:yang:yangtools:test:union", "2015-01-21", "wrapper");
+ // private static final QName WRAP_LEAF_QNAME = QName.create(WRAPPER_QNAME, "wrap");
+
+ // @Test
+ // public void unionTest() {
+ // TopLevel topLevel = TopLevelBuilder.getDefaultInstance(TEST_STRING);
+ // Wrapper wrapper = new WrapperBuilder().setWrap(topLevel).build();
+ // NormalizedNode topLevelEntry = codecContext.toNormalizedNode(InstanceIdentifier.create(Wrapper.class),
+ // wrapper).getValue();
+ //
+ // ContainerNode containerNode = ImmutableContainerNodeBuilder.create()
+ // .withNodeIdentifier(new NodeIdentifier(WRAPPER_QNAME))
+ // .withChild(ImmutableNodes.leafNode(WRAP_LEAF_QNAME, TEST_STRING))
+ // .build();
+ // Assert.assertEquals(topLevelEntry, containerNode);
+ // }
+ //
+ // @Test
+ // public void bug5446Test() {
+ // IpAddressBinary ipAddress = IpAddressBinaryBuilder.getDefaultInstance("fwAAAQ==");
+ // Root root = new RootBuilder().setIpAddress(ipAddress).build();
+ // NormalizedNode rootNode = codecContext.toNormalizedNode(InstanceIdentifier.create(Root.class), root)
+ // .getValue();
+ //
+ // Entry<InstanceIdentifier<?>, DataObject> rootEntry = codecContext.fromNormalizedNode(
+ // YangInstanceIdentifier.of(rootNode.getIdentifier().getNodeType()), rootNode);
+ //
+ // DataObject rootObj = rootEntry.getValue();
+ // assertTrue(rootObj instanceof Root);
+ // IpAddressBinary desIpAddress = ((Root) rootObj).getIpAddress();
+ // assertEquals(ipAddress, desIpAddress);
+ // }
}
+++ /dev/null
-/*
- * Copyright (c) 2016 Intel Corporation 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.dom.codec.impl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Map.Entry;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.bug._6006.rev160607.IdentOne;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.bug._6006.rev160607.UnionNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.bug._6006.rev160607.UnionNodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.bug._6006.rev160607.UnionType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.bug._6006.rev160607.UnionTypeBuilder;
-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 class UnionTypeWithIdentityrefTest extends AbstractBindingCodecTest {
- private static final String IDENT_ONE_STRING = "IdentOne";
- public static final QName NODE_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:mdsal:test:bug:6066",
- "2016-06-07", "union-node");
- public static final QName NODE_LEAF_QNAME = QName.create(NODE_QNAME, "value");
-
- private DataObject createValueNode(final String valueString) {
- UnionType unionType = UnionTypeBuilder.getDefaultInstance(valueString);
- UnionNode unionNode = new UnionNodeBuilder().setValue(unionType).build();
- NormalizedNode normalizedUnionNode = codecContext
- .toNormalizedNode(InstanceIdentifier.builder(UnionNode.class).build(), unionNode)
- .getValue();
-
- Entry<InstanceIdentifier<?>, DataObject> unionNodeEntry = codecContext.fromNormalizedNode(
- YangInstanceIdentifier.of(normalizedUnionNode.getIdentifier().getNodeType()), normalizedUnionNode);
- DataObject unionNodeObj = unionNodeEntry.getValue();
- assertTrue(unionNodeObj instanceof UnionNode);
- return unionNodeObj;
- }
-
- @Test
- public void bug6006Test() {
- DataObject unionNodeObj = createValueNode(IDENT_ONE_STRING);
- UnionType unionTypeObj = ((UnionNode) unionNodeObj).getValue();
- assertEquals(null, unionTypeObj.getUint8());
- assertEquals(IdentOne.class, unionTypeObj.getIdentityref());
- }
-
- @Test
- public void bug6112Test() {
- DataObject unionNodeObj = createValueNode("1");
- UnionType unionTypeObj = ((UnionNode) unionNodeObj).getValue();
- assertEquals(Uint8.valueOf(1), unionTypeObj.getUint8());
- assertEquals(null, unionTypeObj.getIdentityref());
- }
-}
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.binding.generator.BindingGeneratorUtil;
import org.opendaylight.mdsal.binding.generator.impl.reactor.TypeReference.ResolvedLeafref;
-import org.opendaylight.mdsal.binding.model.api.AccessModifier;
import org.opendaylight.mdsal.binding.model.api.ConcreteType;
import org.opendaylight.mdsal.binding.model.api.Enumeration;
import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
addUnits(builder, typedef);
makeSerializable(builder);
- final GeneratedTransferObject ret = builder.build();
-
- // Define a corresponding union builder. Typedefs are always anchored at a Java package root,
- // so we are placing the builder alongside the union.
- final GeneratedTOBuilder unionBuilder = builderFactory.newGeneratedTOBuilder(unionBuilderName(typeName));
- unionBuilder.setIsUnionBuilder(true);
- unionBuilder.addMethod("getDefaultInstance")
- .setAccessModifier(AccessModifier.PUBLIC)
- .setStatic(true)
- .setReturnType(ret)
- .addParameter(Types.STRING, "defaultValue");
- auxiliaryGeneratedTypes.add(unionBuilder.build());
-
- return ret;
- }
-
- // FIXME: this can be a source of conflicts as we are not guarding against nesting
- private static @NonNull JavaTypeName unionBuilderName(final JavaTypeName unionName) {
- final StringBuilder sb = new StringBuilder();
- for (String part : unionName.localNameComponents()) {
- sb.append(part);
- }
- return JavaTypeName.create(unionName.packageName(), sb.append(BindingMapping.BUILDER_SUFFIX).toString());
+ return builder.build();
}
// FIXME: we should not rely on TypeDefinition
import static org.junit.Assert.assertEquals;
-import java.util.List;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class BinaryTypeTest {
@Test
public void binaryTypeTest() {
- final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(
+ final var genTypes = DefaultBindingGenerator.generateFor(
YangParserTestUtils.parseYangResourceDirectory("/binary-type-test-models"));
- assertEquals(10, genTypes.size());
+ assertEquals(9, genTypes.size());
}
}
@Test
public void testBaseYangTypes() {
- final List<GeneratedType> types = DefaultBindingGenerator.generateFor(
+ final var types = DefaultBindingGenerator.generateFor(
YangParserTestUtils.parseYangResource("/base-yang-types.yang"));
- assertEquals(20, types.size());
+ assertEquals(19, types.size());
}
}
import com.google.common.collect.ImmutableRangeSet;
import com.google.common.collect.Range;
import com.google.common.collect.RangeSet;
-import java.util.List;
import org.junit.Test;
import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.model.api.MethodSignature;
import org.opendaylight.mdsal.binding.model.api.Type;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class Bug1862Test {
@Test
public void restrictedTypedefTransformationTest() {
- final EffectiveModelContext context = YangParserTestUtils.parseYangResources(Bug1862Test.class,
- "/base-yang-types.yang", "/test-type-provider.yang");
- final List<GeneratedType> types = DefaultBindingGenerator.generateFor(context);
- assertEquals(42, types.size());
+ final var types = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResources(Bug1862Test.class,
+ "/base-yang-types.yang", "/test-type-provider.yang"));
+ assertEquals(35, types.size());
final MethodSignature fooGetter = types.stream()
.filter(type -> type.getFullyQualifiedName().equals(
"org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.Foo"))
import static org.junit.Assert.assertEquals;
-import java.util.List;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class ControllerTest {
@Test
public void controllerAugmentationTest() {
- final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResources(
+ final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResources(
ControllerTest.class,
"/controller-models/controller-network.yang", "/controller-models/controller-openflow.yang",
"/ietf-models/ietf-inet-types.yang"));
- assertEquals(56, genTypes.size());
+ assertEquals(53, genTypes.size());
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
public class GenerateInnerClassForBitsAndUnionInLeavesTest {
@Test
public void testInnerClassCreationForBitsAndUnionsInLeafes() {
- final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+ final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
"/bit_and_union_in_leaf.yang"));
- assertNotNull(genTypes);
- assertEquals(7, genTypes.size());
+ assertEquals(4, genTypes.size());
boolean parentContainerFound = false;
boolean bitLeafTOFound = false;
@Test
public void testLeafrefResolving() {
- final EffectiveModelContext context = YangParserTestUtils.parseYangResources(GeneratedTypesLeafrefTest.class,
+ final var context = YangParserTestUtils.parseYangResources(GeneratedTypesLeafrefTest.class,
"/leafref-test-models/abstract-topology@2013-02-08.yang", "/ietf-models/ietf-interfaces.yang",
"/ietf-models/ietf-inet-types.yang", "/ietf-models/ietf-yang-types.yang");
assertEquals(4, context.getModules().size());
- final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(context);
-
- assertEquals(56, genTypes.size());
+ final var genTypes = DefaultBindingGenerator.generateFor(context);
+ assertEquals(53, genTypes.size());
GeneratedTransferObject gtIfcKey = null;
GeneratedType gtIfc = null;
public class GeneratedTypesTest {
@Test
public void testMultipleModulesResolving() {
- final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(
+ final var genTypes = DefaultBindingGenerator.generateFor(
YangParserTestUtils.parseYangResources(GeneratedTypesTest.class,
"/abstract-topology.yang", "/ietf-models/ietf-inet-types.yang"));
-
- assertNotNull(genTypes);
- assertEquals(30, genTypes.size());
+ assertEquals(27, genTypes.size());
}
@Test
*/
@Test
public void mdsal161Test() {
- final Collection<GeneratedType> types = DefaultBindingGenerator.generateFor(
+ final var types = DefaultBindingGenerator.generateFor(
YangParserTestUtils.parseYangResource("/mdsal161.yang"));
assertNotNull(types);
- assertEquals(25, types.size());
+ assertEquals(20, types.size());
assertKeyStructure(types, "org.opendaylight.yang.gen.v1.mdsal161.norev.WithGrpKey");
assertKeyStructure(types, "org.opendaylight.yang.gen.v1.mdsal161.norev.WithGrpExtKey");
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
-import java.util.List;
import org.junit.Test;
import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
public class Mdsal269Test {
@Test
public void mdsal269Test() {
- final List<GeneratedType> generateTypes = DefaultBindingGenerator.generateFor(
+ final var generateTypes = DefaultBindingGenerator.generateFor(
YangParserTestUtils.parseYangResource("/mdsal269.yang"));
- assertNotNull(generateTypes);
- assertEquals(5, generateTypes.size());
+ assertEquals(4, generateTypes.size());
final GeneratedType mplsLabelType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
.equals("org.opendaylight.yang.gen.v1.mdsal269.rev180130.MplsLabel")).findFirst().get();
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
public class Mdsal320Test {
@Test
public void mdsal320Test() {
- final List<GeneratedType> generateTypes = DefaultBindingGenerator.generateFor(
+ final var generateTypes = DefaultBindingGenerator.generateFor(
YangParserTestUtils.parseYangResource("/mdsal320.yang"));
- assertNotNull(generateTypes);
- assertEquals(4, generateTypes.size());
+ assertEquals(2, generateTypes.size());
final GeneratedType foo = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
.equals("org.opendaylight.yang.gen.v1.urn.odl.yt320.norev.Foo")).findFirst().get();
package org.opendaylight.mdsal.binding.generator.impl;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import java.util.List;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class Mdsal324Test {
@Test
public void mdsal324Test() {
- final List<GeneratedType> generateTypes = DefaultBindingGenerator.generateFor(
+ final var generatedTypes = DefaultBindingGenerator.generateFor(
YangParserTestUtils.parseYangResource("/mdsal324.yang"));
- assertNotNull(generateTypes);
- assertEquals(6, generateTypes.size());
+ assertEquals(2, generatedTypes.size());
}
}
package org.opendaylight.mdsal.binding.generator.impl;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import com.google.common.collect.ImmutableSet;
-import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.junit.Test;
public class Mdsal458Test {
@Test
public void testNestedClassFallback() {
- final List<GeneratedType> types = DefaultBindingGenerator.generateFor(
+ final var types = DefaultBindingGenerator.generateFor(
YangParserTestUtils.parseYangResource("/mdsal458.yang"));
- assertNotNull(types);
- assertEquals(3, types.size());
+ assertEquals(2, types.size());
final Set<JavaTypeName> typeNames = types.stream().map(GeneratedType::getIdentifier)
.collect(Collectors.toSet());
assertEquals(ImmutableSet.of(
JavaTypeName.create("org.opendaylight.yang.gen.v1.mdsal458.norev", "ExportedTo"),
- JavaTypeName.create("org.opendaylight.yang.gen.v1.mdsal458.norev", "ExportedToExportedTo$Builder"),
JavaTypeName.create("org.opendaylight.yang.gen.v1.mdsal458.norev", "Mdsal458Data")), typeNames);
}
}
import static org.junit.Assert.assertEquals;
-import java.util.List;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class Mdsal572Test {
@Test
public void mdsal572Test() {
- final List<GeneratedType> types = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
- "/mdsal572.yang"));
- assertEquals(6, types.size());
+ final var types = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource("/mdsal572.yang"));
+ assertEquals(5, types.size());
}
}
package org.opendaylight.mdsal.binding.generator.impl;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import java.util.List;
import org.junit.Test;
public class UnionTypeDefTest {
@Test
public void unionTypeResolvingTest() {
- final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResources(
+ final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResources(
UnionTypeDefTest.class, "/union-test-models/abstract-topology.yang", "/ietf-models/ietf-inet-types.yang"));
-
- assertNotNull("genTypes is null", genTypes);
- assertEquals(34, genTypes.size());
+ assertEquals(29, genTypes.size());
// TODO: implement test
}
@Test
public void unionTypedefLeafrefTest() {
- final List<GeneratedType> generateTypes = DefaultBindingGenerator.generateFor(
+ final var generateTypes = DefaultBindingGenerator.generateFor(
YangParserTestUtils.parseYangResource("/bug8449.yang"));
- assertNotNull(generateTypes);
- assertEquals(6, generateTypes.size());
+ assertEquals(5, generateTypes.size());
final GeneratedType cont = generateTypes.stream()
.filter(type -> type.getName().equals("Cont"))
import java.util.Set;
import org.opendaylight.mdsal.binding.generator.BindingGenerator;
import org.opendaylight.mdsal.binding.model.api.CodeGenerator;
-import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.model.api.Type;
import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
continue;
}
- final GeneratedFileLifecycle kind = type instanceof GeneratedTransferObject
- && ((GeneratedTransferObject) type).isUnionTypeBuilder()
- ? GeneratedFileLifecycle.PERSISTENT : GeneratedFileLifecycle.TRANSIENT;
final GeneratedFilePath file = GeneratedFilePath.ofFilePath(
type.getPackageName().replace('.', File.separatorChar)
+ File.separator + generator.getUnitName(type) + ".java");
+ "generated.", type.getFullyQualifiedName());
continue;
}
- throw new IllegalStateException("Duplicate " + kind + " file '" + file.getPath() + "' for "
- + type.getFullyQualifiedName());
+ throw new IllegalStateException("Duplicate file '" + file.getPath() + "' for "
+ + type.getFullyQualifiedName());
}
- result.put(GeneratedFileType.SOURCE, file, new CodeGeneratorGeneratedFile(kind, generator, type));
+ result.put(GeneratedFileType.SOURCE, file,
+ new CodeGeneratorGeneratedFile(GeneratedFileLifecycle.TRANSIENT, generator, type));
}
}
if (genTO.isUnionType()) {
final UnionTemplate template = new UnionTemplate(genTO);
return template.generate();
- } else if (genTO.isUnionTypeBuilder()) {
- final UnionBuilderTemplate template = new UnionBuilderTemplate(genTO);
- return template.generate();
} else if (genTO.isTypedef()) {
final ClassTemplate template = new ClassTemplate(genTO);
return template.generate();
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. 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.mdsal.binding.model.api.GeneratedTransferObject
-import org.opendaylight.mdsal.binding.model.api.AccessModifier
-
-/**
- * Template for generating JAVA class.
- */
-class UnionBuilderTemplate extends ClassTemplate {
-
- /**
- * Creates instance of this class with concrete <code>genType</code>.
- *
- * @param genType generated transfer object which will be transformed to JAVA class source code
- */
- new(GeneratedTransferObject genType) {
- super(genType)
- }
-
- override body() '''
- «wrapToDocumentation(formatDataForJavaDoc(type, getClarification()))»
- «generatedAnnotation»
- public class «type.name» {
- private «type.name»() {
- //Exists only to defeat instantiation.
- }
-
- «generateMethods»
-
- }
- '''
-
- def private generateMethods() '''
- «FOR method : genTO.methodDefinitions»
- «method.accessModifier.accessModifier»«IF method.static»static«ENDIF»«IF method.final» final«ENDIF» «method.
- returnType.importedName» «method.name»(«method.parameters.generateParameters») {
- throw new «UnsupportedOperationException.importedName»("Not yet implemented");
- }
- «ENDFOR»
- '''
-
- def private String getAccessModifier(AccessModifier modifier) {
- switch (modifier) {
- case AccessModifier.PUBLIC: return "public "
- case AccessModifier.PROTECTED: return "protected "
- case AccessModifier.PRIVATE: return "private "
- default: return ""
- }
- }
-
- def private String getClarification() {
- return
- '''
- 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).
-
- The reason behind putting it under src/main/java is:
- This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- loss of user code.
- '''
- }
-
-}
import org.opendaylight.mdsal.binding.model.api.MethodSignature;
import org.opendaylight.mdsal.binding.model.api.MethodSignature.ValueMechanics;
import org.opendaylight.mdsal.binding.model.api.Type;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class BuilderGeneratorTest {
@Test
public void builderTemplateGenerateToEqualsComparingOrderTest() {
- final EffectiveModelContext context = YangParserTestUtils.parseYangResource(
- "/test-types.yang");
- final List<GeneratedType> types = new DefaultBindingGenerator().generateTypes(context);
- assertEquals(29, types.size());
+ final var context = YangParserTestUtils.parseYangResource("/test-types.yang");
+ final var types = new DefaultBindingGenerator().generateTypes(context);
+ assertEquals(27, types.size());
final BuilderTemplate bt = BuilderGenerator.templateForType(
types.stream().filter(t -> t.getName().equals("Nodes")).findFirst().orElseThrow());
assertTrue(new File(parent, "Nodes.java").exists());
assertTrue(new File(parent, "NodesBuilder.java").exists());
assertTrue(new File(parent, "Alg.java").exists());
- assertTrue(new File(parent, "NodesIdUnionBuilder.java").exists());
- CompilationTestUtils.assertFilesCount(parent, 6);
+ CompilationTestUtils.assertFilesCount(parent, 5);
// Test if sources are compilable
CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
generateTestSources("/compilation/typedef", sourcesOutputDir);
final File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO);
- final File bitsExt = new File(parent, "BitsExt.java");
- final File int32Ext0 = new File(parent, "Int32Ext0.java");
- final File int32Ext1 = new File(parent, "Int32Ext1.java");
- final File int32Ext2 = new File(parent, "Int32Ext2.java");
- final File myDecimalType = new File(parent, "MyDecimalType.java");
- final File stringExt1 = new File(parent, "StringExt1.java");
- final File stringExt2 = new File(parent, "StringExt2.java");
- final File stringExt3 = new File(parent, "StringExt3.java");
- final File unionExt1 = new File(parent, "UnionExt1.java");
- final File unionExt2 = new File(parent, "UnionExt2.java");
- final File unionExt3 = new File(parent, "UnionExt3.java");
- final File unionExt4 = new File(parent, "UnionExt4.java");
- assertTrue(bitsExt.exists());
- assertTrue(int32Ext0.exists());
- assertTrue(int32Ext1.exists());
- assertTrue(int32Ext2.exists());
- assertTrue(myDecimalType.exists());
- assertTrue(stringExt1.exists());
- assertTrue(stringExt2.exists());
- assertTrue(stringExt3.exists());
- assertTrue(unionExt1.exists());
- assertTrue(unionExt2.exists());
- assertTrue(unionExt3.exists());
- assertTrue(unionExt4.exists());
- CompilationTestUtils.assertFilesCount(parent, 34);
+ assertTrue(new File(parent, "BitsExt.java").exists());
+ assertTrue(new File(parent, "Int32Ext0.java").exists());
+ assertTrue(new File(parent, "Int32Ext1.java").exists());
+ assertTrue(new File(parent, "Int32Ext2.java").exists());
+ assertTrue(new File(parent, "MyDecimalType.java").exists());
+ assertTrue(new File(parent, "StringExt1.java").exists());
+ assertTrue(new File(parent, "StringExt2.java").exists());
+ assertTrue(new File(parent, "StringExt3.java").exists());
+ assertTrue(new File(parent, "UnionExt1.java").exists());
+ assertTrue(new File(parent, "UnionExt2.java").exists());
+ assertTrue(new File(parent, "UnionExt3.java").exists());
+ assertTrue(new File(parent, "UnionExt4.java").exists());
+ CompilationTestUtils.assertFilesCount(parent, 31);
// Test if sources are compilable
CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
*/
package org.opendaylight.mdsal.binding.java.api.generator;
-import static org.junit.Assert.assertFalse;
-import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.FS;
-import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.GENERATOR_OUTPUT_PATH;
+import static org.junit.Assert.assertEquals;
import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.cleanUp;
import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.testCompilation;
import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.List;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
public class UnionTypedefUnusedImportTest extends BaseCompilationTest {
-
@Test
public void testUnionTypedefUnusedImport() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("union-typedef");
- final List<GeneratedType> types = generateTestSources("/compilation/union-typedef", sourcesOutputDir);
-
- final boolean isUsedImport = containsImport(
- "org.opendaylight.yang.gen.v1.org.opendaylight.yangtools.union.typedef.rev130208.TypedefUnion");
- assertFalse(String.format("Class shouldn't contain import for this type '%s'", types.get(1).getName()),
- isUsedImport);
+ final var types = generateTestSources("/compilation/union-typedef", sourcesOutputDir);
+ assertEquals(2, types.size());
final File compiledOutputDir = CompilationTestUtils.compilerOutput("union-typedef");
testCompilation(sourcesOutputDir, compiledOutputDir);
cleanUp(sourcesOutputDir, compiledOutputDir);
}
-
- private static String readFile(final String path, final Charset encoding) throws IOException {
- byte[] encoded = Files.readAllBytes(Paths.get(path));
- return new String(encoded, encoding);
- }
-
- private static boolean containsImport(final String fullImport) throws URISyntaxException, IOException {
- final String filePath = GENERATOR_OUTPUT_PATH + FS + "union-typedef" + FS + "org" + FS + "opendaylight" + FS
- + "yang" + FS + "gen" + FS + "v1" + FS + "org" + FS + "opendaylight" + FS + "yangtools" + FS + "union"
- + FS + "typedef" + FS + "rev141124" + FS + "TypedefUnionBuilder.java";
- final String fileContent = readFile(filePath, StandardCharsets.UTF_8);
-
- if (fileContent.contains(fullImport)) {
- return true;
- }
- return false;
- }
}
*/
boolean isUnionType();
- boolean isUnionTypeBuilder();
-
Restrictions getRestrictions();
default Optional<? extends GeneratedProperty> findProperty(final String name) {
*/
void setIsUnion(boolean isUnion);
- void setIsUnionBuilder(boolean isUnionTypeBuilder);
-
void setSUID(GeneratedPropertyBuilder suid);
}
private GeneratedTransferObject extendsType;
private boolean isTypedef = false;
private boolean isUnionType = false;
- private boolean isUnionTypeBuilder = false;
private TypeDefinition<?> baseType = null;
AbstractGeneratedTOBuilder(final JavaTypeName identifier) {
@Override
public final GeneratedTOBuilder setExtendsType(final GeneratedTransferObject genTransObj) {
Preconditions.checkArgument(genTransObj != null, "Generated Transfer Object cannot be null!");
- this.extendsType = genTransObj;
+ extendsType = genTransObj;
return this;
}
@Override
public final GeneratedTOBuilder addEqualsIdentity(final GeneratedPropertyBuilder property) {
- this.equalsProperties = LazyCollections.lazyAdd(this.equalsProperties, property);
+ equalsProperties = LazyCollections.lazyAdd(equalsProperties, property);
return this;
}
@Override
public final GeneratedTOBuilder addHashIdentity(final GeneratedPropertyBuilder property) {
- this.hashProperties = LazyCollections.lazyAdd(this.hashProperties, property);
+ hashProperties = LazyCollections.lazyAdd(hashProperties, property);
return this;
}
@Override
public final GeneratedTOBuilder addToStringProperty(final GeneratedPropertyBuilder property) {
- this.toStringProperties = LazyCollections.lazyAdd(this.toStringProperties, property);
+ toStringProperties = LazyCollections.lazyAdd(toStringProperties, property);
return this;
}
@Override
public final void setTypedef(final boolean newIsTypedef) {
- this.isTypedef = newIsTypedef;
+ isTypedef = newIsTypedef;
}
@Override
public final void setBaseType(final TypeDefinition<?> typeDef) {
- this.baseType = typeDef;
+ baseType = typeDef;
}
@Override
public final void setIsUnion(final boolean newIsUnion) {
- this.isUnionType = newIsUnion;
+ isUnionType = newIsUnion;
}
@Override
return isUnionType;
}
- @Override
- public final void setIsUnionBuilder(final boolean newIsUnionTypeBuilder) {
- this.isUnionTypeBuilder = newIsUnionTypeBuilder;
- }
-
abstract static class AbstractGeneratedTransferObject extends AbstractGeneratedType implements
GeneratedTransferObject {
private final boolean isTypedef;
private final TypeDefinition<?> baseType;
private final boolean isUnionType;
- private final boolean isUnionTypeBuilder;
AbstractGeneratedTransferObject(final AbstractGeneratedTOBuilder builder) {
super(builder);
- this.extendsType = builder.extendsType;
+ extendsType = builder.extendsType;
// FIXME: if these fields were guaranteed to be constant, we could perhaps
// cache and reuse them between instances...
- this.equalsProperties = toUnmodifiableProperties(builder.equalsProperties);
- this.hashCodeProperties = toUnmodifiableProperties(builder.hashProperties);
- this.stringProperties = toUnmodifiableProperties(builder.toStringProperties);
-
- this.isTypedef = builder.isTypedef;
- this.baseType = builder.baseType;
- this.isUnionType = builder.isUnionType;
- this.isUnionTypeBuilder = builder.isUnionTypeBuilder;
+ equalsProperties = toUnmodifiableProperties(builder.equalsProperties);
+ hashCodeProperties = toUnmodifiableProperties(builder.hashProperties);
+ stringProperties = toUnmodifiableProperties(builder.toStringProperties);
+
+ isTypedef = builder.isTypedef;
+ baseType = builder.baseType;
+ isUnionType = builder.isUnionType;
}
@Override
public final boolean isTypedef() {
- return this.isTypedef;
+ return isTypedef;
}
@Override
public final TypeDefinition<?> getBaseType() {
- return this.baseType;
+ return baseType;
}
@Override
public final boolean isUnionType() {
- return this.isUnionType;
- }
-
- @Override
- public final boolean isUnionTypeBuilder() {
- return this.isUnionTypeBuilder;
+ return isUnionType;
}
@Override
public final GeneratedTransferObject getSuperType() {
- return this.extendsType;
+ return extendsType;
}
@Override
public final List<GeneratedProperty> getEqualsIdentifiers() {
- return this.equalsProperties;
+ return equalsProperties;
}
@Override
public final List<GeneratedProperty> getHashCodeIdentifiers() {
- return this.hashCodeProperties;
+ return hashCodeProperties;
}
@Override
public final List<GeneratedProperty> getToStringIdentifiers() {
- return this.stringProperties;
+ return stringProperties;
}
@Override
JavaTypeName.create("org.opendaylight.yangtools.test", "Test"));
genTOBuilder.setTypedef(true);
genTOBuilder.setIsUnion(true);
- genTOBuilder.setIsUnionBuilder(true);
genTOBuilder.setDescription("test description");
genTOBuilder.setModuleName("test-module");
genTOBuilder.setReference("http://tools.ietf.org/html/rfc6020");
assertTrue(genTO.isTypedef());
assertTrue(genTO.isUnionType());
- assertTrue(genTO.isUnionTypeBuilder());
assertEquals("test description", genTO.getDescription());
assertEquals("test-module", genTO.getModuleName());
assertEquals("http://tools.ietf.org/html/rfc6020", genTO.getReference());
+++ /dev/null
-package org.opendaylight.yang.gen.v1.bug5446.rev151105;
-
-/**
- * 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).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-public class IpAddressBinaryBuilder {
- public static IpAddressBinary getDefaultInstance(java.lang.String defaultValue) {
- return new IpAddressBinary(Ipv4AddressBinary.getDefaultInstance(defaultValue));
- }
-
- public static IpAddressBinary getDefaultInstance(byte[] defaultValue) {
- if (defaultValue.length == 4) {
- return new IpAddressBinary(new Ipv4AddressBinary(defaultValue));
- } else if (defaultValue.length == 16) {
- return new IpAddressBinary(new Ipv6AddressBinary(defaultValue));
- }
- return null;
- }
-}
+++ /dev/null
-package org.opendaylight.yang.gen.v1.bug8449.rev170516;
-import org.opendaylight.yang.gen.v1.bug8449.rev170516.ContInt32.RefUnionInt32;
-
-/**
- * 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).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-public class ContInt32RefUnionInt32Builder {
-
- public static RefUnionInt32 getDefaultInstance(java.lang.String defaultValue) {
- throw new java.lang.UnsupportedOperationException("Not yet implemented");
- }
-
-}
+++ /dev/null
-package org.opendaylight.yang.gen.v1.bug8449.rev170516;
-import org.opendaylight.yang.gen.v1.bug8449.rev170516.Cont.Ref;
-
-/**
- * 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).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-public class ContRefBuilder {
-
- public static Ref getDefaultInstance(java.lang.String defaultValue) {
- throw new java.lang.UnsupportedOperationException("Not yet implemented");
- }
-
-}
+++ /dev/null
-package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701;
-
-
-
-/**
- * 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).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-public class Int32StringUnionBuilder {
-
- public static Int32StringUnion getDefaultInstance(final java.lang.String defaultValue) {
- try {
- return new Int32StringUnion(Integer.parseInt(defaultValue));
- } catch (final NumberFormatException e) {
- return new Int32StringUnion(defaultValue);
- }
- }
-
-}
+++ /dev/null
-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).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-public class UnionTypeBuilder {
-
- public static UnionType getDefaultInstance(final java.lang.String defaultValue) {
- if (defaultValue.equals("IdentOne")) {
- return new UnionType(IdentOne.class);
- }
- if (defaultValue.equals("IdentTwo")) {
- return new UnionType(IdentTwo.class);
- }
-
- try {
- return new UnionType(Uint8.valueOf(defaultValue));
- } catch (NumberFormatException e) {
- /* do nothing */
- }
-
- throw new IllegalArgumentException("Unknown UnionType string " + defaultValue);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.union.rev150121;
-
-/**
- * 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).
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- */
-public class TopLevelBuilder {
-
- public static TopLevel getDefaultInstance(java.lang.String defaultValue) {
- if (defaultValue.length() <= 4) {
- return new TopLevel(new NonUnionTestType(defaultValue));
- }
- else {
- return new TopLevel(UnionTestTypeBuilder.getDefaultInstance(defaultValue));
- }
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.union.rev150121;
-
-/**
- * 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).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-public class UnionTestTypeBuilder {
-
- public static UnionTestType getDefaultInstance(java.lang.String defaultValue) {
- if (defaultValue.length() > 8) {
- return new UnionTestType(new LowestLevel1(defaultValue));
- } else {
- return new UnionTestType(new LowestLevel2(defaultValue));
- }
- }
-
-}
+++ /dev/null
-package org.opendaylight.yang.gen.v1.urn.test.rev170101;
-import org.opendaylight.yang.gen.v1.urn.test.rev170101.Cont.VlanId;
-
-
-/**
- * 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).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
- */
-public class ContVlanIdBuilder {
-
- public static VlanId getDefaultInstance(java.lang.String defaultValue) {
- throw new java.lang.UnsupportedOperationException("Not yet implemented");
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 ZTE, Inc. 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.yang.gen.v1.urn.test.unsigned.rev180408;
-
-/**
- * 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).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- */
-public class NumberUnionBuilder {
- private NumberUnionBuilder() {
- //Exists only to defeat instantiation.
- }
-
- public static NumberUnion getDefaultInstance(String defaultValue) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-
-/**
- *
- */
-public class HostBuilder {
-
- private static final Pattern IPV4_PATTERN = Pattern.compile("(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\\p{N}\\p{L}]+)?");
- private static final Pattern IPV6_PATTERN1 = Pattern.compile("((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\\p{N}\\p{L}]+)?");
- private static final Pattern IPV6_PATTERN2 = Pattern.compile("(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(%.+)?");
- private static final Pattern DOMAIN_PATTERN = Pattern.compile("((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)|\\.");
-
- private HostBuilder() {
-
- }
-
- public static Host getDefaultInstance(final String defaultValue) {
- final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue);
- final Matcher ipv6Matcher1 = IPV6_PATTERN1.matcher(defaultValue);
- final Matcher ipv6Matcher2 = IPV6_PATTERN2.matcher(defaultValue);
- final Matcher domainMatcher = DOMAIN_PATTERN.matcher(defaultValue);
-
- List<String> matchers = new ArrayList<>(3);
- if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) {
- matchers.add(Ipv6Address.class.getSimpleName());
- }
-
- // Ipv4 and Domain Name patterns are not exclusive
- // Address 127.0.0.1 matches both patterns
- // This way Ipv4 address is preferred to domain name
- if (ipv4Matcher.matches()) {
- matchers.add(Ipv4Address.class.getSimpleName());
- } else if (domainMatcher.matches()) {
- matchers.add(DomainName.class.getSimpleName());
- }
-
- if (matchers.size() > 1) {
- throw new IllegalArgumentException("Cannot create Host from " + defaultValue + ". Value is ambigious for "
- + matchers);
- }
-
- if (ipv4Matcher.matches()) {
- Ipv4Address ipv4 = new Ipv4Address(defaultValue);
- IpAddress ipAddress = new IpAddress(ipv4);
- return new Host(ipAddress);
- }
- if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) {
- Ipv6Address ipv6 = new Ipv6Address(defaultValue);
- IpAddress ipAddress = new IpAddress(ipv6);
- return new Host(ipAddress);
- }
- if (domainMatcher.matches()) {
- DomainName domainName = new DomainName(defaultValue);
- return new Host(domainName);
- }
- throw new IllegalArgumentException("Cannot create Host from " + defaultValue);
- }
-
-}
*/
package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
+import static com.google.common.base.Verify.verify;
+
import com.google.common.annotations.Beta;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.model.ietf.util.AbstractIetfInetUtil;
/**
@Beta
public final class IetfInetUtil extends AbstractIetfInetUtil<Ipv4Address, Ipv4AddressNoZone, Ipv4Prefix, Ipv6Address,
Ipv6AddressNoZone, Ipv6Prefix, IpAddress, IpAddressNoZone, IpPrefix> {
- public static final IetfInetUtil INSTANCE = new IetfInetUtil();
+ public static final @NonNull IetfInetUtil INSTANCE = new IetfInetUtil();
+
+ private static final Pattern HOST_IPV4_PATTERN = Pattern.compile(
+ "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"
+ + "(%[\\p{N}\\p{L}]+)?");
+ private static final Pattern HOST_IPV6_PATTERN1 = Pattern.compile("((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}"
+ +"((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}"
+ + "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\\p{N}\\p{L}]+)?");
+ private static final Pattern HOST_IPV6_PATTERN2 = Pattern.compile(
+ "(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(%.+)?");
+ private static final Pattern HOST_DOMAIN_PATTERN = Pattern.compile(
+ "((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?"
+ +"[a-zA-Z0-9]\\.?)|\\.");
+
+ private static final Pattern IPADDRESS_IPV4_PATTERN;
+ static {
+ verify(Ipv4Address.PATTERN_CONSTANTS.size() == 1);
+ IPADDRESS_IPV4_PATTERN = Pattern.compile(Ipv4Address.PATTERN_CONSTANTS.get(0));
+ }
+
+ private static final Pattern IPADDRESS_NO_ZONE_IPV4_PATTERN = Pattern.compile("[0-9\\.]*");
+ private static final Pattern IPADDRESS_NO_ZONE_IPV6_PATTERN = Pattern.compile("[0-9a-fA-F:\\.]*");
+
+ private static final Pattern IPPREFIX_IPV4_PATTERN;
+ static {
+ verify(Ipv4Prefix.PATTERN_CONSTANTS.size() == 1);
+ IPPREFIX_IPV4_PATTERN = Pattern.compile(Ipv4Prefix.PATTERN_CONSTANTS.get(0));
+ }
private IetfInetUtil() {
super(Ipv4AddressNoZone.class, Ipv4Prefix.class, Ipv6AddressNoZone.class, Ipv6Prefix.class);
}
+ @Beta
+ public static Host hostFor(final String str) {
+ final Matcher ipv4Matcher = HOST_IPV4_PATTERN.matcher(str);
+ final Matcher ipv6Matcher1 = HOST_IPV6_PATTERN1.matcher(str);
+ final Matcher ipv6Matcher2 = HOST_IPV6_PATTERN2.matcher(str);
+ final Matcher domainMatcher = HOST_DOMAIN_PATTERN.matcher(str);
+ List<String> matchers = new ArrayList<>(3);
+ if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) {
+ matchers.add(Ipv6Address.class.getSimpleName());
+ }
+ // Ipv4 and Domain Name patterns are not exclusive
+ // Address 127.0.0.1 matches both patterns
+ // This way Ipv4 address is preferred to domain name
+ if (ipv4Matcher.matches()) {
+ matchers.add(Ipv4Address.class.getSimpleName());
+ } else if (domainMatcher.matches()) {
+ matchers.add(DomainName.class.getSimpleName());
+ }
+ if (matchers.size() > 1) {
+ throw new IllegalArgumentException("Cannot create Host from " + str + ". Value is ambigious for "
+ + matchers);
+ }
+ if (ipv4Matcher.matches()) {
+ Ipv4Address ipv4 = new Ipv4Address(str);
+ IpAddress ipAddress = new IpAddress(ipv4);
+ return new Host(ipAddress);
+ }
+ if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) {
+ Ipv6Address ipv6 = new Ipv6Address(str);
+ IpAddress ipAddress = new IpAddress(ipv6);
+ return new Host(ipAddress);
+ }
+ if (domainMatcher.matches()) {
+ DomainName domainName = new DomainName(str);
+ return new Host(domainName);
+ }
+ throw new IllegalArgumentException("Cannot create Host from " + str);
+ }
+
+ @Beta
+ public static IpAddress ipAddressFor(final String str) {
+ return IPADDRESS_IPV4_PATTERN.matcher(str).matches() ? new IpAddress(new Ipv4Address(str))
+ : new IpAddress(new Ipv6Address(str));
+ }
+
+ @Beta
+ public static IpAddressNoZone ipAddressNoZoneFor(final String str) {
+ if (IPADDRESS_NO_ZONE_IPV4_PATTERN.matcher(str).matches()) {
+ return new IpAddressNoZone(new Ipv4AddressNoZone(str));
+ } else if (IPADDRESS_NO_ZONE_IPV6_PATTERN.matcher(str).matches()) {
+ return new IpAddressNoZone(new Ipv6AddressNoZone(str));
+ } else {
+ throw new IllegalArgumentException("Cannot create IpAddress from " + str);
+ }
+ }
+
+ @Beta
+ public static IpPrefix ipPrefixFor(final String defaultValue) {
+ return IPPREFIX_IPV4_PATTERN.matcher(defaultValue).matches() ? new IpPrefix(new Ipv4Prefix(defaultValue))
+ : new IpPrefix(new Ipv6Prefix(defaultValue));
+ }
+
@Override
protected IpAddress ipv4Address(final Ipv4AddressNoZone addr) {
return new IpAddress(addr);
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
-
-import static com.google.common.base.Verify.verify;
-
-import java.util.regex.Pattern;
-
-/**
- * Builder for {@link IpAddress} instances.
- */
-public class IpAddressBuilder {
- private static final Pattern IPV4_PATTERN;
-
- static {
- verify(Ipv4Address.PATTERN_CONSTANTS.size() == 1);
- IPV4_PATTERN = Pattern.compile(Ipv4Address.PATTERN_CONSTANTS.get(0));
- }
-
- private IpAddressBuilder() {
-
- }
-
- public static IpAddress getDefaultInstance(final String defaultValue) {
- return IPV4_PATTERN.matcher(defaultValue).matches() ? new IpAddress(new Ipv4Address(defaultValue))
- : new IpAddress(new Ipv6Address(defaultValue));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
-
-import java.util.regex.Pattern;
-
-public class IpAddressNoZoneBuilder {
-
- private static final Pattern IPV4_NO_ZONE_PATTERN =
- Pattern.compile("[0-9\\.]*");
- private static final Pattern IPV6_NO_ZONE_PATTERN1 =
- Pattern.compile("[0-9a-fA-F:\\.]*");
-
- public static IpAddressNoZone getDefaultInstance(final String defaultValue) {
- if (IPV4_NO_ZONE_PATTERN.matcher(defaultValue).matches()) {
- return new IpAddressNoZone((new Ipv4AddressNoZone(defaultValue)));
- } else if (IPV6_NO_ZONE_PATTERN1.matcher(defaultValue).matches()) {
- return new IpAddressNoZone((new Ipv6AddressNoZone(defaultValue)));
- } else {
- throw new IllegalArgumentException("Cannot create IpAddress from " + defaultValue);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
-
-import static com.google.common.base.Verify.verify;
-
-import java.util.regex.Pattern;
-
-/**
- * Builder for {@link IpPrefix} instances.
- */
-public class IpPrefixBuilder {
- private static final Pattern IPV4_PATTERN;
-
- static {
- verify(Ipv4Prefix.PATTERN_CONSTANTS.size() == 1);
- IPV4_PATTERN = Pattern.compile(Ipv4Prefix.PATTERN_CONSTANTS.get(0));
- }
-
- private IpPrefixBuilder() {
-
- }
-
- public static IpPrefix getDefaultInstance(final String defaultValue) {
- return IPV4_PATTERN.matcher(defaultValue).matches() ? new IpPrefix(new Ipv4Prefix(defaultValue))
- : new IpPrefix(new Ipv6Prefix(defaultValue));
- }
-}
package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
-import java.lang.reflect.Constructor;
import org.junit.Test;
public class HostBuilderTest {
-
@Test
public void testGetDefaultInstance() throws Exception {
- final Constructor<HostBuilder> constructor = HostBuilder.class.getDeclaredConstructor();
- assertFalse(constructor.isAccessible());
- constructor.setAccessible(true);
- final HostBuilder newInstance = constructor.newInstance();
- assertNotNull(newInstance);
-
testIpv4("1.1.1.1");
testIpv4("192.168.155.100");
testIpv4("1.192.1.221");
testDomain("test");
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testIllegalArgumentException1() {
- HostBuilder.getDefaultInstance("2001:0DB8::CD3/60");
+ assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.hostFor("2001:0DB8::CD3/60"));
}
@Test(expected = IllegalArgumentException.class)
}
private static void testIpv4(final String ip) {
- final Host defaultInstance = HostBuilder.getDefaultInstance(ip);
+ final Host defaultInstance = IetfInetUtil.hostFor(ip);
assertEquals(new Host(new IpAddress(new Ipv4Address(ip))), defaultInstance);
}
private static void testIpv6(final String ip) {
- final Host defaultInstance = HostBuilder.getDefaultInstance(ip);
+ final Host defaultInstance = IetfInetUtil.hostFor(ip);
assertEquals(new Host(new IpAddress(new Ipv6Address(ip))), defaultInstance);
}
private static void testDomain(final String ip) {
- final Host defaultInstance = HostBuilder.getDefaultInstance(ip);
+ final Host defaultInstance = IetfInetUtil.hostFor(ip);
assertEquals(new Host(new DomainName(ip)), defaultInstance);
}
}
\ No newline at end of file
package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
-import java.lang.reflect.Constructor;
import org.junit.Test;
public class IpAddressBuilderTest {
-
@Test
public void testGetDefaultInstance() throws Exception {
- final Constructor<IpAddressBuilder> constructor = IpAddressBuilder.class.getDeclaredConstructor();
- assertFalse(constructor.isAccessible());
- constructor.setAccessible(true);
- final IpAddressBuilder newInstance = constructor.newInstance();
- assertNotNull(newInstance);
-
testIpv4("1.1.1.1");
testIpv4("192.168.155.100");
testIpv4("1.192.1.221");
testIpv6("::");
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testIllegalArgumentException1() {
- IpAddressBuilder.getDefaultInstance("badIp");
+ assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.ipAddressFor("badIp"));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testIllegalArgumentException2() {
- IpAddressBuilder.getDefaultInstance("2001:0DB8::CD3/60");
+ assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.ipAddressFor("2001:0DB8::CD3/60"));
}
private static void testIpv4(final String ip) {
- final IpAddress defaultInstance = IpAddressBuilder.getDefaultInstance(ip);
+ final IpAddress defaultInstance = IetfInetUtil.ipAddressFor(ip);
assertEquals(new IpAddress(new Ipv4Address(ip)), defaultInstance);
}
private static void testIpv6(final String ip) {
- final IpAddress defaultInstance = IpAddressBuilder.getDefaultInstance(ip);
+ final IpAddress defaultInstance = IetfInetUtil.ipAddressFor(ip);
assertEquals(new IpAddress(new Ipv6Address(ip)), defaultInstance);
}
}
\ No newline at end of file
package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
-import java.lang.reflect.Constructor;
import org.junit.Test;
public class IpAddressNoZoneBuilderTest {
-
@Test
public void testGetDefaultInstance() throws Exception {
- final Constructor<IpAddressNoZoneBuilder> constructor = IpAddressNoZoneBuilder.class.getDeclaredConstructor();
- assertFalse(constructor.isAccessible());
- constructor.setAccessible(true);
- final IpAddressNoZoneBuilder newInstance = constructor.newInstance();
- assertNotNull(newInstance);
-
testIpv4("1.1.1.1");
testIpv4("192.168.155.100");
testIpv4("1.192.1.221");
testIpv6("::");
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testIllegalArgumentException() {
- IpAddressNoZoneBuilder.getDefaultInstance("2001:0DB8::CD3/60");
+ assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.ipAddressNoZoneFor("2001:0DB8::CD3/60"));
}
private static void testIpv4(final String ip) {
- final IpAddressNoZone defaultInstance = IpAddressNoZoneBuilder.getDefaultInstance(ip);
- assertEquals(new IpAddressNoZone(new Ipv4AddressNoZone(ip)), defaultInstance);
+ assertEquals(new IpAddressNoZone(new Ipv4AddressNoZone(ip)), IetfInetUtil.ipAddressNoZoneFor(ip));
}
private static void testIpv6(final String ip) {
- final IpAddressNoZone defaultInstance = IpAddressNoZoneBuilder.getDefaultInstance(ip);
- assertEquals(new IpAddressNoZone(new Ipv6AddressNoZone(ip)), defaultInstance);
+ assertEquals(new IpAddressNoZone(new Ipv6AddressNoZone(ip)), IetfInetUtil.ipAddressNoZoneFor(ip));
}
}
\ No newline at end of file
package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
-import java.lang.reflect.Constructor;
import org.junit.Test;
public class IpPrefixBuilderTest {
-
@Test
public void testGetDefaultInstance() throws Exception {
- final Constructor<IpPrefixBuilder> constructor = IpPrefixBuilder.class.getDeclaredConstructor();
- assertFalse(constructor.isAccessible());
- constructor.setAccessible(true);
- final IpPrefixBuilder newInstance = constructor.newInstance();
- assertNotNull(newInstance);
-
testIpv6("ff00::/8");
testIpv4("192.0.2.1/24");
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testIllegalArgumentException1() {
- IpPrefixBuilder.getDefaultInstance("badIp");
+ assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.ipPrefixFor("badIp"));
}
private static void testIpv4(final String ip) {
- final IpPrefix defaultInstance = IpPrefixBuilder.getDefaultInstance(ip);
- assertEquals(new IpPrefix(new Ipv4Prefix(ip)), defaultInstance);
+ assertEquals(new IpPrefix(new Ipv4Prefix(ip)), IetfInetUtil.ipPrefixFor(ip));
}
private static void testIpv6(final String ip) {
- final IpPrefix defaultInstance = IpPrefixBuilder.getDefaultInstance(ip);
- assertEquals(new IpPrefix(new Ipv6Prefix(ip)), defaultInstance);
+ assertEquals(new IpPrefix(new Ipv6Prefix(ip)), IetfInetUtil.ipPrefixFor(ip));
}
}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2018, 2022 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204;
+
+import static com.google.common.base.Verify.verify;
+import static com.google.common.base.Verify.verifyNotNull;
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Verify;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import java.util.Arrays;
+import java.util.regex.Pattern;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+
+/**
+ * Utility methods for dealing with unions in {@code ietf-routing-types.yang}.
+ */
+@Beta
+@NonNullByDefault
+public final class IetfRoutingUtils {
+ private static final ImmutableMap<Ipv4MulticastSourceAddress.Enumeration, Ipv4MulticastSourceAddress>
+ ENUMERATED_IPV4_MCAST_SRC = Arrays.stream(Ipv4MulticastSourceAddress.Enumeration.values()).collect(
+ Maps.toImmutableEnumMap(Verify::verifyNotNull, Ipv4MulticastSourceAddress::new));
+ private static final ImmutableMap<Ipv6MulticastSourceAddress.Enumeration, Ipv6MulticastSourceAddress>
+ ENUMERATED_IPV6_MCAST_SRC = Arrays.stream(Ipv6MulticastSourceAddress.Enumeration.values()).collect(
+ Maps.toImmutableEnumMap(Verify::verifyNotNull, Ipv6MulticastSourceAddress::new));
+ private static final ImmutableMap<TimerValueMilliseconds.Enumeration, TimerValueMilliseconds>
+ ENUMERATED_TIMERVAR_MS = Arrays.stream(TimerValueMilliseconds.Enumeration.values())
+ .collect(Maps.toImmutableEnumMap(Verify::verifyNotNull, TimerValueMilliseconds::new));
+ private static final ImmutableMap<TimerValueSeconds16.Enumeration, TimerValueSeconds16> ENUMERATED_TIMERVAL_16 =
+ Arrays.stream(TimerValueSeconds16.Enumeration.values())
+ .collect(Maps.toImmutableEnumMap(Verify::verifyNotNull, TimerValueSeconds16::new));
+ private static final ImmutableMap<TimerValueSeconds32.Enumeration, TimerValueSeconds32> ENUMERATED_TIMERVAL_32 =
+ Arrays.stream(TimerValueSeconds32.Enumeration.values())
+ .collect(Maps.toImmutableEnumMap(Verify::verifyNotNull, TimerValueSeconds32::new));
+
+ private static final Pattern IP_MCAST_GRP_ADDR_IPV4_PATTERN;
+
+ static {
+ verify(Ipv4Address.PATTERN_CONSTANTS.size() == 1);
+ IP_MCAST_GRP_ADDR_IPV4_PATTERN = Pattern.compile(Ipv4MulticastGroupAddress.PATTERN_CONSTANTS.get(0));
+ }
+
+ private IetfRoutingUtils() {
+ // Hidden on purpose
+ }
+
+ public static IpMulticastGroupAddress ipMulticastGroupAddressFor(final String str) {
+ return IP_MCAST_GRP_ADDR_IPV4_PATTERN.matcher(str).matches()
+ ? new IpMulticastGroupAddress(new Ipv4MulticastGroupAddress(str))
+ : new IpMulticastGroupAddress(new Ipv6MulticastGroupAddress(str));
+ }
+
+ public static Ipv4MulticastSourceAddress ipv4MulticastSourceAddressFor(final String str) {
+ return Ipv4MulticastSourceAddress.Enumeration.forName(str)
+ .map(ENUMERATED_IPV4_MCAST_SRC::get)
+ .orElse(new Ipv4MulticastSourceAddress(new Ipv4Address(str)));
+ }
+
+ public static Ipv4MulticastSourceAddress ipv4MulticastSourceAddressFor(
+ final Ipv4MulticastSourceAddress.Enumeration enumeration) {
+ return verifyNotNull(ENUMERATED_IPV4_MCAST_SRC.get(requireNonNull(enumeration)));
+ }
+
+ public static Ipv6MulticastSourceAddress ipv6MulticastSourceAddressFor(final String str) {
+ return Ipv6MulticastSourceAddress.Enumeration.forName(str)
+ .map(ENUMERATED_IPV6_MCAST_SRC::get)
+ .orElse(new Ipv6MulticastSourceAddress(new Ipv6Address(str)));
+ }
+
+ public static Ipv6MulticastSourceAddress ipv6MulticastSourceAddressFor(
+ final Ipv6MulticastSourceAddress.Enumeration enumeration) {
+ return verifyNotNull(ENUMERATED_IPV6_MCAST_SRC.get(requireNonNull(enumeration)));
+ }
+
+ public static TimerValueMilliseconds timerValueMillisecondsFor(final String str) {
+ return TimerValueMilliseconds.Enumeration.forName(str)
+ .map(ENUMERATED_TIMERVAR_MS::get)
+ .orElse(new TimerValueMilliseconds(Uint32.valueOf(str)));
+ }
+
+ public static TimerValueMilliseconds timerValueMillisecondsFor(
+ final TimerValueMilliseconds.Enumeration enumeration) {
+ return verifyNotNull(ENUMERATED_TIMERVAR_MS.get(requireNonNull(enumeration)));
+ }
+
+
+ public static TimerValueSeconds16 timerValueSeconds16For(final String str) {
+ return TimerValueSeconds16.Enumeration.forName(str).map(ENUMERATED_TIMERVAL_16::get)
+ .orElse(new TimerValueSeconds16(Uint16.valueOf(str)));
+ }
+
+ public static TimerValueSeconds16 timerValueSeconds16For(
+ final TimerValueSeconds16.Enumeration enumeration) {
+ return verifyNotNull(ENUMERATED_TIMERVAL_16.get(requireNonNull(enumeration)));
+ }
+
+ public static TimerValueSeconds32 timerValueSeconds32For(final String defaultValue) {
+ return TimerValueSeconds32.Enumeration.forName(defaultValue)
+ .map(ENUMERATED_TIMERVAL_32::get)
+ .orElse(new TimerValueSeconds32(Uint32.valueOf(defaultValue)));
+ }
+
+ public static TimerValueSeconds32 timerValueSeconds32For(final TimerValueSeconds32.Enumeration enumeration) {
+ return verifyNotNull(ENUMERATED_TIMERVAL_32.get(requireNonNull(enumeration)));
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2018 Pantheon Technologies, 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204;
-
-import static com.google.common.base.Verify.verify;
-
-import com.google.common.annotations.Beta;
-import java.util.regex.Pattern;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-
-/**
- * Builder for {@link IpMulticastGroupAddress} instances.
- *
- * @author Robert Varga
- */
-@Beta
-@NonNullByDefault
-public final class IpMulticastGroupAddressBuilder {
- private static final Pattern IPV4_PATTERN;
-
- static {
- verify(Ipv4Address.PATTERN_CONSTANTS.size() == 1);
- IPV4_PATTERN = Pattern.compile(Ipv4MulticastGroupAddress.PATTERN_CONSTANTS.get(0));
- }
-
- private IpMulticastGroupAddressBuilder() {
- //Exists only to defeat instantiation.
- }
-
- public static IpMulticastGroupAddress getDefaultInstance(final String defaultValue) {
- return IPV4_PATTERN.matcher(defaultValue).matches()
- ? new IpMulticastGroupAddress(new Ipv4MulticastGroupAddress(defaultValue))
- : new IpMulticastGroupAddress(new Ipv6MulticastGroupAddress(defaultValue));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 Pantheon Technologies, 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204;
-
-import static com.google.common.base.Verify.verifyNotNull;
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Verify;
-import com.google.common.collect.Maps;
-import java.util.Arrays;
-import java.util.Map;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Ipv4MulticastSourceAddress.Enumeration;
-
-/**
- * Builder for {@link IpMulticastGroupAddress} instances.
- *
- * @author Robert Varga
- */
-@Beta
-@NonNullByDefault
-public final class Ipv4MulticastSourceAddressBuilder {
- private static final Map<Enumeration, Ipv4MulticastSourceAddress> ENUMERATED = Arrays.stream(Enumeration.values())
- .collect(Maps.toImmutableEnumMap(Verify::verifyNotNull, Ipv4MulticastSourceAddress::new));
-
- private Ipv4MulticastSourceAddressBuilder() {
- //Exists only to defeat instantiation.
- }
-
- public static Ipv4MulticastSourceAddress getDefaultInstance(final String defaultValue) {
- return Enumeration.forName(defaultValue).map(ENUMERATED::get)
- .orElse(new Ipv4MulticastSourceAddress(new Ipv4Address(defaultValue)));
- }
-
- public static Ipv4MulticastSourceAddress forEnumeration(final Enumeration enumeration) {
- return verifyNotNull(ENUMERATED.get(requireNonNull(enumeration)));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 Pantheon Technologies, 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204;
-
-import static com.google.common.base.Verify.verifyNotNull;
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Verify;
-import com.google.common.collect.Maps;
-import java.util.Arrays;
-import java.util.Map;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Ipv6MulticastSourceAddress.Enumeration;
-
-/**
- * Builder for {@link IpMulticastGroupAddress} instances.
- *
- * @author Robert Varga
- */
-@Beta
-@NonNullByDefault
-public final class Ipv6MulticastSourceAddressBuilder {
- private static final Map<Enumeration, Ipv6MulticastSourceAddress> ENUMERATED = Arrays.stream(Enumeration.values())
- .collect(Maps.toImmutableEnumMap(Verify::verifyNotNull, Ipv6MulticastSourceAddress::new));
-
- private Ipv6MulticastSourceAddressBuilder() {
-
- }
-
- public static Ipv6MulticastSourceAddress getDefaultInstance(final String defaultValue) {
- return Enumeration.forName(defaultValue).map(ENUMERATED::get)
- .orElse(new Ipv6MulticastSourceAddress(new Ipv6Address(defaultValue)));
- }
-
- public static Ipv6MulticastSourceAddress forEnumeration(final Enumeration enumeration) {
- return verifyNotNull(ENUMERATED.get(requireNonNull(enumeration)));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 Pantheon Technologies, 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204;
-
-import com.google.common.annotations.Beta;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-import java.util.AbstractMap.SimpleImmutableEntry;
-import java.util.Map.Entry;
-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;
-
-/**
- * Builder for {@link MplsLabel} instances.
- *
- * @author Robert Varga
- */
-@Beta
-@NonNullByDefault
-public final class MplsLabelBuilder {
- private static final Logger LOG = LoggerFactory.getLogger(MplsLabelBuilder.class);
-
- @SuppressWarnings("null")
- private static final LoadingCache<Entry<ClassLoader, String>, Optional<MplsLabel>> CLASS_CACHE =
- CacheBuilder.newBuilder()
- .weakKeys().build(new CacheLoader<Entry<ClassLoader, String>, Optional<MplsLabel>>() {
- @Override
- public Optional<MplsLabel> load(final Entry<ClassLoader, String> key) {
- return loadClass(key.getKey(), key.getValue());
- }
- });
-
- private MplsLabelBuilder() {
-
- }
-
- public static MplsLabel getDefaultInstance(final String defaultValue) {
- if (defaultValue.startsWith("interface ")) {
- final Optional<MplsLabel> optStatic = CLASS_CACHE.getUnchecked(
- new SimpleImmutableEntry<>(MplsLabelBuilder.class.getClassLoader(), defaultValue));
- if (optStatic.isPresent()) {
- return optStatic.get();
- }
-
- final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
- if (tccl != null) {
- final Optional<MplsLabel> optThreadLocal = CLASS_CACHE.getUnchecked(
- new SimpleImmutableEntry<>(tccl, defaultValue));
- if (optThreadLocal.isPresent()) {
- return optThreadLocal.get();
- }
- }
- }
-
- return new MplsLabel(new MplsLabelGeneralUse(Uint32.valueOf(defaultValue)));
- }
-
- static Optional<MplsLabel> loadClass(final ClassLoader loader, final String key) {
- final Class<?> cls;
- try {
- cls = ClassLoaderUtils.loadClass(loader, key);
- } catch (ClassNotFoundException e) {
- LOG.debug("%s not found in classloader of %s", key, loader);
- return Optional.empty();
- }
-
- final Class<? extends MplsLabelSpecialPurposeValue> cast;
- try {
- cast = cls.asSubclass(MplsLabelSpecialPurposeValue.class);
- } catch (ClassCastException e) {
- LOG.warn("%s does not implement %s", MplsLabelSpecialPurposeValue.class);
- return Optional.empty();
- }
-
- return Optional.of(new MplsLabel(cast));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 Pantheon Technologies, 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204;
-
-import static com.google.common.base.Verify.verifyNotNull;
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Verify;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-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.
- *
- * @author Robert Varga
- */
-@Beta
-@NonNullByDefault
-public final class TimerValueMillisecondsBuilder {
- private static final ImmutableMap<Enumeration, TimerValueMilliseconds> ENUMERATED =
- Arrays.stream(Enumeration.values())
- .collect(Maps.toImmutableEnumMap(Verify::verifyNotNull, TimerValueMilliseconds::new));
-
- private TimerValueMillisecondsBuilder() {
-
- }
-
- public static TimerValueMilliseconds getDefaultInstance(final String defaultValue) {
- return Enumeration.forName(defaultValue).map(ENUMERATED::get)
- .orElse(new TimerValueMilliseconds(Uint32.valueOf(defaultValue)));
- }
-
- public static TimerValueMilliseconds forEnumeration(final Enumeration enumeration) {
- return verifyNotNull(ENUMERATED.get(requireNonNull(enumeration)));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 Pantheon Technologies, 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204;
-
-import static com.google.common.base.Verify.verifyNotNull;
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Verify;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-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.
- *
- * @author Robert Varga
- */
-@Beta
-@NonNullByDefault
-public final class TimerValueSeconds16Builder {
- private static final ImmutableMap<Enumeration, TimerValueSeconds16> ENUMERATED =
- Arrays.stream(Enumeration.values())
- .collect(Maps.toImmutableEnumMap(Verify::verifyNotNull, TimerValueSeconds16::new));
-
- private TimerValueSeconds16Builder() {
-
- }
-
- public static TimerValueSeconds16 getDefaultInstance(final String defaultValue) {
- return Enumeration.forName(defaultValue).map(ENUMERATED::get)
- .orElse(new TimerValueSeconds16(Uint16.valueOf(defaultValue)));
- }
-
- public static TimerValueSeconds16 forEnumeration(final Enumeration enumeration) {
- return verifyNotNull(ENUMERATED.get(requireNonNull(enumeration)));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 Pantheon Technologies, 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204;
-
-import static com.google.common.base.Verify.verifyNotNull;
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Verify;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-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.
- *
- * @author Robert Varga
- */
-@Beta
-@NonNullByDefault
-public final class TimerValueSeconds32Builder {
- private static final ImmutableMap<Enumeration, TimerValueSeconds32> ENUMERATED = Arrays.stream(Enumeration.values())
- .collect(Maps.toImmutableEnumMap(Verify::verifyNotNull, TimerValueSeconds32::new));
-
- private TimerValueSeconds32Builder() {
-
- }
-
- public static TimerValueSeconds32 getDefaultInstance(final String defaultValue) {
- return Enumeration.forName(defaultValue).map(ENUMERATED::get)
- .orElse(new TimerValueSeconds32(Uint32.valueOf(defaultValue)));
- }
-
- public static TimerValueSeconds32 forEnumeration(final Enumeration enumeration) {
- return verifyNotNull(ENUMERATED.get(requireNonNull(enumeration)));
- }
-}
<groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
<artifactId>rfc8519-ietf-ethertypes</artifactId>
- <version>10.0.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>${project.artifactId}</name>
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 {
+/**
+ * Utility methods for dealing with {@link Ethertype}.
+ */
+public final class EthertypeUtils {
private static final CharMatcher DIGITS = CharMatcher.inRange('0', '9');
private static final EnumMap<Enumeration, Ethertype> ENUM_ETHERTYPES;
ENUM_ETHERTYPES = map;
}
- private EthertypeBuilder() {
+ private EthertypeUtils() {
//Exists only to defeat instantiation.
}
--- /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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104;
+
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.CommonLeafs;
+import org.opendaylight.yangtools.yang.common.Revision;
+
+/**
+ * Utility methods for converting legacy RFC7895 {@code modules-state} Revision to and from various representations.
+ */
+@SuppressWarnings("deprecation")
+public final class LegacyRevisionUtils {
+ private static final CommonLeafs.@NonNull Revision EMPTY_REVISION = new CommonLeafs.Revision("");
+
+ private LegacyRevisionUtils() {
+ // Hidden on purpose
+ }
+
+ /**
+ * Return an empty {@link CommonLeafs.Revision}.
+ *
+ * @return An empty Revision.
+ */
+ public static CommonLeafs.@NonNull Revision emptyRevision() {
+ return EMPTY_REVISION;
+ }
+
+ public static CommonLeafs.@NonNull Revision fromString(final String defaultValue) {
+ return defaultValue.isEmpty() ? EMPTY_REVISION
+ : new CommonLeafs.Revision(new RevisionIdentifier(defaultValue));
+ }
+
+ /**
+ * Create a {@link CommonLeafs.Revision} from an optional {@link Revision}.
+ *
+ * @param revision Optional {@link Revision}
+ * @return A Revision
+ * @throws NullPointerException if {@code revision} is null
+ */
+ public static CommonLeafs.@NonNull Revision fromYangCommon(final Optional<Revision> revision) {
+ return revision.map(rev -> new CommonLeafs.Revision(new RevisionIdentifier(rev.toString())))
+ .orElse(EMPTY_REVISION);
+ }
+
+ /**
+ * Create an optional {@link Revision} from a {@link CommonLeafs.Revision}.
+ *
+ * @param revision A Revision
+ * @return Optional {@link Revision}
+ * @throws NullPointerException if {@code revision} is null
+ */
+ public static Optional<Revision> toYangCommon(final CommonLeafs.Revision revision) {
+ final var id = revision.getRevisionIdentifier();
+ return id != null ? Optional.of(Revision.of(id.getValue())) : Optional.empty();
+ }
+}
+
--- /dev/null
+package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104;
+
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.ImportOnlyModule;
+import org.opendaylight.yangtools.yang.common.Revision;
+
+/**
+ * Utility methods for converting legacy RFC8525 Revision to and from various representations.
+ */
+public final class RevisionUtils {
+ private static final ImportOnlyModule.@NonNull Revision EMPTY_REVISION = new ImportOnlyModule.Revision("");
+
+ private RevisionUtils() {
+ // Hidden on purpose
+ }
+
+ /**
+ * Return an empty {@link ImportOnlyModule.Revision}.
+ *
+ * @return An empty Revision.
+ */
+ public static ImportOnlyModule.@NonNull Revision emptyRevision() {
+ return EMPTY_REVISION;
+ }
+
+ public static ImportOnlyModule.@NonNull Revision fromString(final String defaultValue) {
+ return defaultValue.isEmpty() ? EMPTY_REVISION
+ : new ImportOnlyModule.Revision(new RevisionIdentifier(defaultValue));
+ }
+
+ /**
+ * Create a {@link ImportOnlyModule.Revision} from an optional {@link Revision}.
+ *
+ * @param revision Optional {@link Revision}
+ * @return A Revision
+ * @throws NullPointerException if revision is null
+ */
+ public static ImportOnlyModule.@NonNull Revision fromYangCommon(final Optional<Revision> revision) {
+ return revision.map(rev -> new ImportOnlyModule.Revision(new RevisionIdentifier(rev.toString())))
+ .orElse(EMPTY_REVISION);
+ }
+
+ /**
+ * Create an optional {@link Revision} from a {@link ImportOnlyModule.Revision}.
+ *
+ * @param revision A Revision
+ * @return Optional {@link Revision}
+ * @throws NullPointerException if revision is null
+ */
+ public static Optional<Revision> toYangCommon(final ImportOnlyModule.Revision revision) {
+ final var id = revision.getRevisionIdentifier();
+ return id != null ? Optional.of(Revision.of(id.getValue())) : Optional.empty();
+ }
+}
+++ /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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list;
-
-import java.util.Optional;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.RevisionIdentifier;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.CommonLeafs.Revision;
-
-@SuppressWarnings("deprecation")
-public final class CommonLeafsRevisionBuilder {
- private static final Revision EMPTY_REVISION = new Revision("");
-
- private CommonLeafsRevisionBuilder() {
-
- }
-
- /**
- * Return an empty {@link Revision}.
- *
- * @return An empty Revision.
- */
- public static Revision emptyRevision() {
- return EMPTY_REVISION;
- }
-
- /**
- * Create a {@link Revision} from an optional {@link org.opendaylight.yangtools.yang.common.Revision}.
- *
- * @param revision Optional {@link org.opendaylight.yangtools.yang.common.Revision}
- * @return A Revision
- * @throws NullPointerException if revision is null
- */
- public static Revision fromYangCommon(final Optional<org.opendaylight.yangtools.yang.common.Revision> revision) {
- return revision.map(rev -> new Revision(new RevisionIdentifier(rev.toString()))).orElse(EMPTY_REVISION);
- }
-
- /**
- * Create an optional {@link org.opendaylight.yangtools.yang.common.Revision} from a {@link Revision}.
- *
- * @param revision A Revision
- * @return Optional {@link org.opendaylight.yangtools.yang.common.Revision}
- * @throws NullPointerException if revision is null
- */
- public static Optional<org.opendaylight.yangtools.yang.common.Revision> toYangCommon(final Revision revision) {
- final @Nullable RevisionIdentifier id = revision.getRevisionIdentifier();
- return id != null ? Optional.of(org.opendaylight.yangtools.yang.common.Revision.of(id.getValue()))
- : Optional.empty();
- }
-
- public static Revision getDefaultInstance(final String defaultValue) {
- return defaultValue.isEmpty() ? EMPTY_REVISION : new Revision(new RevisionIdentifier(defaultValue));
- }
-}
-
+++ /dev/null
-package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters;
-
-import java.util.Optional;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.RevisionIdentifier;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.ImportOnlyModule.Revision;
-
-public final class ImportOnlyModuleRevisionBuilder {
- private static final Revision EMPTY_REVISION = new Revision("");
-
- private ImportOnlyModuleRevisionBuilder() {
-
- }
-
- /**
- * Return an empty {@link Revision}.
- *
- * @return An empty Revision.
- */
- public static Revision emptyRevision() {
- return EMPTY_REVISION;
- }
-
- /**
- * Create a {@link Revision} from an optional {@link org.opendaylight.yangtools.yang.common.Revision}.
- *
- * @param revision Optional {@link org.opendaylight.yangtools.yang.common.Revision}
- * @return A Revision
- * @throws NullPointerException if revision is null
- */
- public static Revision fromYangCommon(final Optional<org.opendaylight.yangtools.yang.common.Revision> revision) {
- return revision.map(rev -> new Revision(new RevisionIdentifier(rev.toString()))).orElse(EMPTY_REVISION);
- }
-
- /**
- * Create an optional {@link org.opendaylight.yangtools.yang.common.Revision} from a {@link Revision}.
- *
- * @param revision A Revision
- * @return Optional {@link org.opendaylight.yangtools.yang.common.Revision}
- * @throws NullPointerException if revision is null
- */
- public static Optional<org.opendaylight.yangtools.yang.common.Revision> toYangCommon(final Revision revision) {
- final @Nullable RevisionIdentifier id = revision.getRevisionIdentifier();
- return id != null ? Optional.of(org.opendaylight.yangtools.yang.common.Revision.of(id.getValue()))
- : Optional.empty();
- }
-
- public static Revision getDefaultInstance(final String defaultValue) {
- return defaultValue.isEmpty() ? EMPTY_REVISION : new Revision(new RevisionIdentifier(defaultValue));
- }
-}
<groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
<artifactId>rfc8776-ietf-te-types</artifactId>
- <version>10.0.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>${project.artifactId}</name>
+++ /dev/null
-/*
- * Copyright (c) 2020 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev200610;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString;
-
-public class AdminGroupsBuilder {
- private AdminGroupsBuilder() {
- // Hidden on purpose
- }
-
- public static AdminGroups getDefaultInstance(final String defaultValue) {
- final HexString hex = new HexString(defaultValue);
- return defaultValue.length() <= 11 ? new AdminGroups(new AdminGroup(hex))
- : new AdminGroups(new ExtendedAdminGroup(hex));
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2020, 2022 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev200610;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString;
+import org.opendaylight.yangtools.yang.common.Uint32;
+
+/**
+ * Utility methods for dealing with {@code ietf-te-types.yang} unions.
+ */
+public final class IetfTeUtil {
+ private static final @NonNull TeTopologyId EMPTY_TE_TOPOLOGY_ID = new TeTopologyId("");
+
+ private IetfTeUtil() {
+ // Hidden on purpose
+ }
+
+ public static @NonNull AdminGroups admingGroupsFor(final String str) {
+ final HexString hex = new HexString(str);
+ return str.length() <= 11 ? new AdminGroups(new AdminGroup(hex)) : new AdminGroups(new ExtendedAdminGroup(hex));
+ }
+
+ public static @NonNull TeTopologyId teTopologyIdFor(final String str) {
+ return str.isEmpty() ? EMPTY_TE_TOPOLOGY_ID : new TeTopologyId(str);
+ }
+
+ public static @NonNull TeTpId teTpIdFor(final String str) {
+ return str.indexOf('.') == -1 && str.indexOf(':') == -1
+ ? new TeTpId(Uint32.valueOf(str)) : new TeTpId(IetfInetUtil.ipAddressFor(str));
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2020 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev200610;
-
-public class PathAttributeFlagsBuilder {
- private PathAttributeFlagsBuilder() {
- // Hidden on purpose
- }
-
- public static PathAttributeFlags getDefaultInstance(final String defaultValue) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev200610;
-
-public class TeTopologyIdBuilder {
- private static final TeTopologyId EMPTY = new TeTopologyId("");
-
- private TeTopologyIdBuilder() {
- // Hidden on purpose
- }
-
- public static TeTopologyId getDefaultInstance(final String defaultValue) {
- return defaultValue.isEmpty() ? EMPTY : new TeTopologyId(defaultValue);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2020 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev200610;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
-import org.opendaylight.yangtools.yang.common.Uint32;
-
-public class TeTpIdBuilder {
- private TeTpIdBuilder() {
- // Hidden on purpose
- }
-
- public static TeTpId getDefaultInstance(final String defaultValue) {
- return defaultValue.indexOf('.') == -1 && defaultValue.indexOf(':') == -1
- ? new TeTpId(Uint32.valueOf(defaultValue))
- : new TeTpId(IpAddressBuilder.getDefaultInstance(defaultValue));
- }
-}
import org.opendaylight.mdsal.yanglib.api.SourceReference;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.datastores.rev180214.Operational;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.LegacyRevisionUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.RevisionIdentifier;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.RevisionUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.CommonLeafs;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.CommonLeafsRevisionBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.Module.ConformanceType;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.ImportOnlyModuleRevisionBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.Datastore;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.DatastoreKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.ModuleSet;
@SuppressWarnings("deprecation")
private static SourceReference sourceRefFor(final CommonLeafs obj, final Uri uri) {
final var sourceId = RevisionSourceIdentifier.create(obj.getName().getValue(),
- CommonLeafsRevisionBuilder.toYangCommon(obj.getRevision()));
+ LegacyRevisionUtils.toYangCommon(obj.getRevision()));
if (uri != null) {
try {
return SourceReference.of(sourceId, new URL(uri.getValue()));
// TODO: take deviations/features into account
for (var mod : modSet.nonnullImportOnlyModule().values()) {
- fillSource(librarySources, mod.getName(), ImportOnlyModuleRevisionBuilder.toYangCommon(mod.getRevision()),
+ fillSource(librarySources, mod.getName(), RevisionUtils.toYangCommon(mod.getRevision()),
mod.getLocation());
mod.nonnullSubmodule().values().forEach(sub -> {
fillSource(librarySources, sub.getName(), toYangCommon(sub.getRevision()), sub.getLocation());