import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.List;
}
private static TwoLevelListChanged createTestData() {
- final TwoLevelListChangedBuilder tb = new TwoLevelListChangedBuilder();
- tb.setTopLevelList(ImmutableList.of(new TopLevelListBuilder().withKey(new TopLevelListKey("test")).build()));
- return tb.build();
+ final TopLevelListKey key = new TopLevelListKey("test");
+ return new TwoLevelListChangedBuilder()
+ .setTopLevelList(ImmutableMap.of(key, new TopLevelListBuilder().withKey(key).build()))
+ .build();
}
@Test
*/
package org.opendaylight.mdsal.binding.dom.adapter.test;
-import java.util.ArrayList;
+import java.util.Collections;
import org.junit.Test;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
public void testDelete() {
DataBroker dataBroker = getDataBroker();
WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
- ArrayList<TopLevelList> list = new ArrayList<>();
- list.add(new TopLevelListBuilder().setName("name").build());
- TopBuilder builder = new TopBuilder().setTopLevelList(list);
+
+ final TopLevelList item = new TopLevelListBuilder().setName("name").build();
+ TopBuilder builder = new TopBuilder().setTopLevelList(Collections.singletonMap(item.key(), item));
writeTransaction.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Top.class), builder.build());
assertCommit(writeTransaction.commit());
protected static final <E extends DataObject & Identifiable<?>> void streamMap(final Class<E> childClass,
final DataObjectStreamer<E> childStreamer, final DataObjectSerializerRegistry registry,
- final BindingStreamEventWriter writer, final List<? extends E> value) throws IOException {
+ final BindingStreamEventWriter writer, final Map<?, ? extends E> value) throws IOException {
if (value != null) {
writer.startMapNode(childClass, value.size());
- commonStreamList(registry, writer, childStreamer, value);
+ commonStreamList(registry, writer, childStreamer, value.values());
}
}
BindingStreamEventWriter.class, List.class);
private static final StackManipulation STREAM_MAP = invokeMethod(DataObjectStreamer.class,
"streamMap", Class.class, DataObjectStreamer.class, DataObjectSerializerRegistry.class,
- BindingStreamEventWriter.class, List.class);
+ BindingStreamEventWriter.class, Map.class);
private static final StackManipulation STREAM_ORDERED_MAP = invokeMethod(DataObjectStreamer.class,
"streamOrderedMap", Class.class, DataObjectStreamer.class, DataObjectSerializerRegistry.class,
BindingStreamEventWriter.class, List.class);
final String getterName = getter.getName();
final Type childType = props.get(getterName);
verify(childType instanceof ParameterizedType, "Unexpected type %s for %s", childType, getterName);
- final Type valueType = ((ParameterizedType) childType).getActualTypeArguments()[0];
+ final Type[] params = ((ParameterizedType) childType).getActualTypeArguments();
+ final ListSchemaNode listSchema = (ListSchemaNode) childSchema;
final Class<?> valueClass;
- try {
- valueClass = loader.loadClass(valueType.getFullyQualifiedName());
- } catch (ClassNotFoundException e) {
- throw new LinkageError("Failed to load " + valueType, e);
+ if (!listSchema.isUserOrdered() && !listSchema.getKeyDefinition().isEmpty()) {
+ loadTypeClass(loader, params[0]);
+ valueClass = loadTypeClass(loader, params[1]);
+ } else {
+ valueClass = loadTypeClass(loader, params[0]);
}
- return listChildStream(getter, valueClass.asSubclass(DataObject.class), (ListSchemaNode) childSchema);
+
+ return listChildStream(getter, valueClass.asSubclass(DataObject.class), listSchema);
}
if (childSchema instanceof ChoiceSchemaNode) {
return choiceChildStream(getter);
}
}
+ private static Class<?> loadTypeClass(final CodecClassLoader loader, final Type type) {
+ try {
+ return loader.loadClass(type.getFullyQualifiedName());
+ } catch (ClassNotFoundException e) {
+ throw new LinkageError("Failed to load " + type, e);
+ }
+ }
+
private static final class SerializeImplementation implements Implementation {
private final List<ChildStream> children;
private final StackManipulation startEvent;
import static java.util.Objects.requireNonNull;
import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.IDENTIFIABLE_KEY_NAME;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMap.Builder;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.invoke.WrongMethodTypeException;
import java.lang.reflect.Method;
+import java.util.Collection;
import java.util.List;
+import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Identifiable;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-final class KeyedListNodeCodecContext<D extends DataObject & Identifiable<?>> extends ListNodeCodecContext<D> {
+abstract class KeyedListNodeCodecContext<D extends DataObject & Identifiable<?>> extends ListNodeCodecContext<D> {
+ private static final class Ordered<D extends DataObject & Identifiable<?>> extends KeyedListNodeCodecContext<D> {
+ Ordered(final DataContainerCodecPrototype<ListSchemaNode> prototype, final Method keyMethod,
+ final IdentifiableItemCodec codec) {
+ super(prototype, keyMethod, codec);
+ }
+ }
+
+ private static final class Unordered<D extends DataObject & Identifiable<?>> extends KeyedListNodeCodecContext<D> {
+ private static final MethodType KEY_TYPE = MethodType.methodType(Object.class, DataObject.class);
+
+ private final MethodHandle keyHandle;
+
+ Unordered(final DataContainerCodecPrototype<ListSchemaNode> prototype, final Method keyMethod,
+ final IdentifiableItemCodec codec) {
+ super(prototype, keyMethod, codec);
+
+ try {
+ this.keyHandle = MethodHandles.publicLookup().unreflect(keyMethod).asType(KEY_TYPE);
+ } catch (IllegalAccessException | WrongMethodTypeException e) {
+ throw new LinkageError("Failed to acquire method " + keyMethod, e);
+ }
+ }
+
+ @Override
+ Map<?, D> fromMap(final MapNode nodes) {
+ final Collection<MapEntryNode> value = nodes.getValue();
+ final Builder<Object, D> builder = ImmutableMap.builderWithExpectedSize(value.size());
+ // FIXME: Could be this lazy transformed map?
+ for (MapEntryNode node : value) {
+ final D entry = fromMapEntry(node);
+ builder.put(getKey(entry), entry);
+ }
+ return builder.build();
+ }
+
+ @SuppressWarnings("checkstyle:illegalCatch")
+ private Object getKey(final D entry) {
+ try {
+ return keyHandle.invokeExact(entry);
+ } catch (Throwable e) {
+ throw new LinkageError("Failed to extract key from " + entry, e);
+ }
+ }
+ }
+
private final IdentifiableItemCodec codec;
- private KeyedListNodeCodecContext(final DataContainerCodecPrototype<ListSchemaNode> prototype,
+ KeyedListNodeCodecContext(final DataContainerCodecPrototype<ListSchemaNode> prototype,
final Method keyMethod, final IdentifiableItemCodec codec) {
super(prototype, keyMethod);
this.codec = requireNonNull(codec);
throw new IllegalStateException("Required method not available", e);
}
- final IdentifiableItemCodec codec = prototype.getFactory().getPathArgumentCodec(bindingClass,
- prototype.getSchema());
- return new KeyedListNodeCodecContext<>(prototype, keyMethod, codec);
+ final ListSchemaNode schema = prototype.getSchema();
+ final IdentifiableItemCodec codec = prototype.getFactory().getPathArgumentCodec(bindingClass, schema);
+ return schema.isUserOrdered() ? new Ordered<>(prototype, keyMethod, codec)
+ : new Unordered<>(prototype, keyMethod, codec);
}
@Override
}
}
- private List<D> fromMap(final MapNode nodes) {
+ Object fromMap(final MapNode nodes) {
final Collection<MapEntryNode> value = nodes.getValue();
final Builder<D> builder = ImmutableList.builderWithExpectedSize(value.size());
// FIXME: Could be this lazy transformed list?
for (MapEntryNode node : value) {
- builder.add(fromMapEntry(node));
+ builder.add(createBindingProxy(node));
}
return builder.build();
}
- private D fromMapEntry(final MapEntryNode node) {
+ final D fromMapEntry(final MapEntryNode node) {
return createBindingProxy(node);
}
private static RpcComplexUsesAugment createComplexData() {
return new RpcComplexUsesAugmentBuilder()
- .setContainerWithUses(new ContainerWithUsesBuilder()
- .setLeafFromGrouping("foo")
- .build())
- .setListViaUses(Collections.emptyList())
+ .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping("foo").build())
+ .setListViaUses(Collections.emptyMap())
.build();
}
}
public class Bug5845booleanKeyTest extends AbstractBindingCodecTest {
@Test
public void testBug5845() throws Exception {
- final BooleanContainer booleanContainer = new BooleanContainerBuilder().setBooleanList(Collections
- .singletonList(new BooleanListBuilder()
- .withKey(new BooleanListKey(true, true))
- .setBooleanLeaf1(true)
- .setBooleanLeaf2(true)
- .build()))
+ final BooleanListKey blk = new BooleanListKey(true, true);
+ final BooleanContainer booleanContainer = new BooleanContainerBuilder()
+ .setBooleanList(Collections.singletonMap(blk, new BooleanListBuilder()
+ .withKey(blk)
+ .setBooleanLeaf1(true)
+ .setBooleanLeaf2(true)
+ .build()))
.build();
- final BooleanContainer booleanContainerInt = new BooleanContainerBuilder().setBooleanListInt(Collections
- .singletonList(new BooleanListIntBuilder()
- .withKey(new BooleanListIntKey((byte) 1))
+ final BooleanListIntKey blik = new BooleanListIntKey((byte) 1);
+ final BooleanContainer booleanContainerInt = new BooleanContainerBuilder()
+ .setBooleanListInt(Collections.singletonMap(blik, new BooleanListIntBuilder()
+ .withKey(blik)
.setBooleanLeafInt((byte) 1)
.build()))
.build();
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.Collection;
-import java.util.List;
+import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode;
private static final NodeIdentifier TOP_LEVEL_LIST_ARG = new NodeIdentifier(TopLevelList.QNAME);
private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
- private static final List<TopLevelList> TWO_LIST = createList(2);
- private static final List<TopLevelList> THREE_LIST = createList(3);
+ private static final Map<TopLevelListKey, TopLevelList> TWO_LIST = createList(2);
+ private static final Map<TopLevelListKey, TopLevelList> THREE_LIST = createList(3);
private static final Top TOP_TWO_LIST_DATA = new TopBuilder().setTopLevelList(TWO_LIST).build();
private static final Top TOP_THREE_LIST_DATA = new TopBuilder().setTopLevelList(THREE_LIST).build();
contNode = registry.getCodecContext().getSubtreeCodec(CONT_PATH);
}
- private static List<TopLevelList> createList(final int num) {
-
- final ImmutableList.Builder<TopLevelList> builder = ImmutableList.builder();
+ private static Map<TopLevelListKey, TopLevelList> createList(final int num) {
+ final ImmutableMap.Builder<TopLevelListKey, TopLevelList> builder = ImmutableMap.builder();
for (int i = 0; i < num; i++) {
final TopLevelListKey key = new TopLevelListKey("test-" + i);
- builder.add(new TopLevelListBuilder().withKey(key).build());
+ builder.put(key, new TopLevelListBuilder().withKey(key).build());
}
return builder.build();
}
final Top input = new TopBuilder().build();
assertNull(input.getTopLevelList());
- assertEquals(ImmutableList.of(), input.nonnullTopLevelList());
+ assertEquals(ImmutableMap.of(), input.nonnullTopLevelList());
final NormalizedNode<?, ?> dom = cachingCodec.serialize(input);
final Top output = cachingCodec.deserialize(dom);
assertTrue(output.equals(input));
assertNull(output.getTopLevelList());
- assertEquals(ImmutableList.of(), output.nonnullTopLevelList());
+ assertEquals(ImmutableMap.of(), output.nonnullTopLevelList());
}
@SafeVarargs
private static RpcComplexUsesAugment createComplexData() {
return new RpcComplexUsesAugmentBuilder()
- .setContainerWithUses(new ContainerWithUsesBuilder()
- .setLeafFromGrouping("foo")
- .build())
- .setListViaUses(Collections.emptyList())
- .build();
+ .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping("foo").build())
+ .setListViaUses(Collections.emptyMap())
+ .build();
}
-
}
assertNotNull(((EmptyLeaf) list).getEmptyType());
}
+ // FIXME: either remove this method or take advantage of it
private static RpcComplexUsesAugment createComplexData() {
return new RpcComplexUsesAugmentBuilder()
- .setContainerWithUses(new ContainerWithUsesBuilder()
- .setLeafFromGrouping("foo")
- .build())
- .setListViaUses(Collections.emptyList())
- .build();
+ .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping("foo").build())
+ .setListViaUses(Collections.emptyMap())
+ .build();
}
-
}
import static org.junit.Assert.assertEquals;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import java.util.Map.Entry;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.mdsal442.keydef.norev.Def;
private static final InstanceIdentifier<Use> USE_IID = InstanceIdentifier.create(Use.class);
private static final Def DEF = new DefBuilder()
- .setLst(ImmutableList.of(new LstBuilder().setFoo("foo").withKey(KEY).build()))
+ .setLst(ImmutableMap.of(KEY, new LstBuilder().setFoo("foo").withKey(KEY).build()))
.build();
private static final Use USE = new UseBuilder()
- .setLst(ImmutableList.of(new LstBuilder().setFoo("foo").withKey(KEY).build()))
+ .setLst(ImmutableMap.of(KEY, new LstBuilder().setFoo("foo").withKey(KEY).build()))
.build();
@Test
for (Entry<Class<? extends Augmentation<Top>>, ? extends Augmentation<Top>> augment : augments.entrySet()) {
topBuilder.addAugmentation(augment.getKey(), augment.getValue());
}
- return topBuilder.setTopLevelList(Collections.emptyList()).build();
+ return topBuilder.setTopLevelList(Collections.emptyMap()).build();
}
@Test
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import java.time.Instant;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TwoLevelListChanged;
private static final QName NAME = QName.create(TopLevelList.QNAME, "name");
private static TwoLevelListChanged createTestBindingData() {
+ final TopLevelListKey key = new TopLevelListKey("test");
return new TwoLevelListChangedBuilder()
- .setTopLevelList(ImmutableList.of(
- new TopLevelListBuilder().withKey(new TopLevelListKey("test")).build()))
+ .setTopLevelList(ImmutableMap.of(key, new TopLevelListBuilder().withKey(key).build()))
.build();
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.GetTopOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.GetTopOutputBuilder;
private static final SchemaPath PUT_TOP_INPUT = SchemaPath.create(true, PUT_TOP, PutTopInput.QNAME);
private static final SchemaPath GET_TOP_OUTPUT = SchemaPath.create(true, GET_TOP, GetTopOutput.QNAME);
+ private static final TopLevelListKey LIST_KEY = new TopLevelListKey("test");
+
@Test
public void testRpcInputToNormalized() {
- final PutTopInputBuilder tb = new PutTopInputBuilder();
- tb.setTopLevelList(ImmutableList.of(new TopLevelListBuilder().withKey(new TopLevelListKey("test")).build()));
- final PutTopInput bindingOriginal = tb.build();
+ final PutTopInput bindingOriginal = new PutTopInputBuilder()
+ .setTopLevelList(ImmutableMap.of(LIST_KEY, new TopLevelListBuilder().withKey(LIST_KEY).build()))
+ .build();
final ContainerNode dom = registry.toNormalizedNodeRpcData(bindingOriginal);
assertNotNull(dom);
assertEquals(PutTopInput.QNAME, dom.getIdentifier().getNodeType());
@Test
public void testRpcOutputToNormalized() {
- final GetTopOutputBuilder tb = new GetTopOutputBuilder();
- tb.setTopLevelList(ImmutableList.of(new TopLevelListBuilder().withKey(new TopLevelListKey("test")).build()));
- final GetTopOutput bindingOriginal = tb.build();
+ final GetTopOutput bindingOriginal = new GetTopOutputBuilder()
+ .setTopLevelList(ImmutableMap.of(LIST_KEY, new TopLevelListBuilder().withKey(LIST_KEY).build()))
+ .build();
final ContainerNode dom = registry.toNormalizedNodeRpcData(bindingOriginal);
assertNotNull(dom);
assertEquals(GetTopOutput.QNAME, dom.getIdentifier().getNodeType());
final DataObject bindingDeserialized = registry.fromNormalizedNodeRpcData(GET_TOP_OUTPUT, dom);
assertEquals(bindingOriginal, bindingDeserialized);
-
}
-
}
import static org.opendaylight.mdsal.binding.model.util.Types.classType;
import static org.opendaylight.mdsal.binding.model.util.Types.listTypeFor;
import static org.opendaylight.mdsal.binding.model.util.Types.listenableFutureTypeFor;
+import static org.opendaylight.mdsal.binding.model.util.Types.mapTypeFor;
import static org.opendaylight.mdsal.binding.model.util.Types.primitiveVoidType;
import static org.opendaylight.mdsal.binding.model.util.Types.typeForClass;
import static org.opendaylight.mdsal.binding.model.util.Types.wildcardTypeFor;
keyTypeBuilder = null;
}
- final ParameterizedType listType = listTypeFor(genType);
+ // Decide whether to generate a List or a Map
+ final ParameterizedType listType;
+ if (keyTypeBuilder != null && !node.isUserOrdered()) {
+ listType = mapTypeFor(keyTypeBuilder, genType);
+ } else {
+ listType = listTypeFor(genType);
+ }
+
constructGetter(parent, listType, node);
constructNonnull(parent, listType, node);
containsInterface("LockType", genType);
genType = checkGeneratedType(genTypes, "PartialLock", pcgPref + ".lock.type"); // case
- containsMethods(genType, new NameTypePattern("getPartialLock", "List<PartialLock>"));
+ containsMethods(genType, new NameTypePattern("getPartialLock", "Map<PartialLockKey,PartialLock>"));
containsInterface("LockType", genType);
genType = checkGeneratedType(genTypes, "Fingerprint", pcgPref + ".lock.type"); // case
genType = checkGeneratedType(genTypes, "UnknownFiles", pcgPref
+ ".netconf.state.datastores.datastore.storage.format"); // case
- containsMethods(genType, new NameTypePattern("getFiles", "List<Files>"));
+ containsMethods(genType, new NameTypePattern("getFiles", "Map<FilesKey,Files>"));
containsInterface("StorageFormat", genType);
// case
return parameterizedTypeFor(MAP_TYPE, keyType, valueType);
}
+ public static boolean isMapType(final ParameterizedType type) {
+ return MAP_TYPE.equals(type.getRawType());
+ }
+
+ public static boolean isMapType(final Type type) {
+ return type instanceof ParameterizedType && isMapType((ParameterizedType) type);
+ }
+
/**
* Returns an instance of {@link ParameterizedType} describing the typed {@link Set}<V> with concrete type
* of value.
val returnType = field.returnType
if (returnType instanceof ParameterizedType) {
if (Types.isListType(returnType)) {
- return generateListSetter(field, returnType.actualTypeArguments.get(0))
+ return generateListSetter(field, returnType.actualTypeArguments.get(0), "")
+ } else if (Types.isMapType(returnType)) {
+ return generateListSetter(field, returnType.actualTypeArguments.get(1), ".values()")
}
}
return generateSimpleSetter(field, returnType)
}
- def private generateListSetter(GeneratedProperty field, Type actualType) '''
+ def private generateListSetter(GeneratedProperty field, Type actualType, String extractor) '''
«val restrictions = restrictionsForSetter(actualType)»
«IF restrictions !== null»
«generateCheckers(field, restrictions, actualType)»
public «type.getName» set«field.getName.toFirstUpper»(final «field.returnType.importedName» values) {
«IF restrictions !== null»
if (values != null) {
- for («actualType.importedName» value : values) {
+ for («actualType.importedName» value : values«extractor») {
«checkArgument(field, restrictions, actualType, "value")»
}
}
*/
package org.opendaylight.mdsal.binding.test.model.util;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
import java.util.Arrays;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
}
public static Top top(final TopLevelList... listItems) {
- return new TopBuilder().setTopLevelList(Arrays.asList(listItems)).build();
+ return new TopBuilder().setTopLevelList(Maps.uniqueIndex(Arrays.asList(listItems), TopLevelList::key)).build();
}
public static TopLevelList topLevelList(final TopLevelListKey key) {
}
public static TreeComplexUsesAugment complexUsesAugment(final ListViaUsesKey... keys) {
- final ImmutableList.Builder<ListViaUses> listViaUses = ImmutableList.builder();
+ final ImmutableMap.Builder<ListViaUsesKey, ListViaUses> listViaUses = ImmutableMap.builder();
for (final ListViaUsesKey key : keys) {
- listViaUses.add(new ListViaUsesBuilder().withKey(key).build());
+ listViaUses.put(key, new ListViaUsesBuilder().withKey(key).build());
}
return new TreeComplexUsesAugmentBuilder().setListViaUses(listViaUses.build()).build();
}
import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL;
-import java.util.Map;
+import java.util.Map.Entry;
import org.junit.Test;
import org.opendaylight.mdsal.binding.api.ReadTransaction;
import org.opendaylight.mdsal.binding.api.WriteTransaction;
@Test
public void testAssertDataObjectsWithComplexTopWithKey() {
AssertDataObjects.assertEqualByText(HEADER + "new TopBuilder >> [\n"
- + " topLevelList = #[\n"
- + " new TopLevelListBuilder >> [\n"
+ + " topLevelList = #{\n"
+ + " new TopLevelListKey(\"foo\") -> new TopLevelListBuilder >> [\n"
+ " name = \"foo\"\n"
+ " addAugmentation(TreeComplexUsesAugment, new TreeComplexUsesAugmentBuilder >> [\n"
+ " containerWithUses = new ContainerWithUsesBuilder >> [\n"
+ " ]\n"
+ " ])\n"
+ " ]\n"
- + " ]\n"
+ + " }\n"
+ "]", ExpectedObjects.top());
}
String expectedTopText = "import static extension org.opendaylight.mdsal.binding.testutils."
+ "XtendBuilderExtensions.operator_doubleGreaterThan\n\n"
+ "new TopBuilder >> [\n"
- + " topLevelList = #[\n"
- + " new TopLevelListBuilder >> [\n"
+ + " topLevelList = #{\n"
+ + " new TopLevelListKey(\"foo\") -> new TopLevelListBuilder >> [\n"
+ " name = \"foo\"\n"
+ " addAugmentation(TreeComplexUsesAugment, new TreeComplexUsesAugmentBuilder >> [\n"
+ " containerWithUses = new ContainerWithUsesBuilder >> [\n"
+ " ]\n"
+ " ])\n"
+ " ]\n"
- + " ]\n"
+ + " }\n"
+ "]";
AssertDataObjects.assertEqualByText(expectedTopText, actualTop);
}
<T extends DataObject> void put(WriteTransaction tx, LogicalDatastoreType store,
- Map.Entry<InstanceIdentifier<T>, T> obj) {
+ Entry<InstanceIdentifier<T>, T> obj) {
tx.put(OPERATIONAL, obj.getKey(), obj.getValue());
}
Top actualTop = readTx.read(OPERATIONAL, id).get().get();
AssertBeans.assertEqualByText("#{\n}", augmentableExtension.getAugmentations(actualTop));
- TopLevelList topLevelList = actualTop.getTopLevelList().get(0);
+ TopLevelList topLevelList = actualTop.getTopLevelList().values().iterator().next();
AssertDataObjects.assertEqualByText("#{\n"
+ " TreeComplexUsesAugment -> new TreeComplexUsesAugmentBuilder >> [\n"
+ " containerWithUses = new ContainerWithUsesBuilder >> [\n"
*/
package org.opendaylight.mdsal.binding.testutils;
+import com.google.common.collect.Maps;
import java.util.Collections;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
public static Top top() {
return new TopBuilder()
- .setTopLevelList(Collections.singletonList(new TopLevelListBuilder()
+ .setTopLevelList(Maps.uniqueIndex(Collections.singletonList(new TopLevelListBuilder()
.setName("foo")
.addAugmentation(TreeComplexUsesAugment.class, new TreeComplexUsesAugmentBuilder()
.setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping("foo").build())
.build())
- .build()))
+ .build()), TopLevelList::key))
.build();
}
}
final List<SourceReference> requiredSources = new ArrayList<>();
final List<SourceReference> librarySources = new ArrayList<>();
- for (Module module : modState.nonnullModule()) {
+ for (Module module : modState.nonnullModule().values()) {
final SourceReference modRef = sourceRefFor(module, module.getSchema());
// TODO: take deviations/features into account
requiredSources.add(modRef);
}
- for (Submodule submodule : module.nonnullSubmodule()) {
+ for (Submodule submodule : module.nonnullSubmodule().values()) {
// Submodules go to library, as they are pulled in as needed
librarySources.add(sourceRefFor(submodule, submodule.getSchema()));
}
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
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.module.set.parameters.Module;
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;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.Schema;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.SchemaKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier;
import org.opendaylight.yangtools.rcf8528.data.util.AbstractMountPointContextFactory;
import org.opendaylight.yangtools.rfc8528.data.api.MountPointContextFactory;
}
private @NonNull SchemaContext bindLibrary(final @NonNull YangLibrary yangLib) throws YangParserException {
- final List<Datastore> datastores = yangLib.nonnullDatastore();
+ final Map<DatastoreKey, Datastore> datastores = yangLib.nonnullDatastore();
checkArgument(!datastores.isEmpty(), "No datastore defined");
final List<SourceReference> requiredSources = new ArrayList<>();
final List<SourceReference> librarySources = new ArrayList<>();
final HashSet<String> moduleSet = findModuleSet(yangLib, findSchemaName(datastores, Operational.QNAME));
- for (ModuleSet modSet : yangLib.nonnullModuleSet()) {
+ for (ModuleSet modSet : yangLib.nonnullModuleSet().values()) {
if (moduleSet.remove(modSet.getName())) {
fillModules(librarySources, requiredSources, modSet);
}
final List<SourceReference> librarySources = new ArrayList<>();
for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list
- .Module module : modState.nonnullModule()) {
+ .Module module : modState.nonnullModule().values()) {
final SourceReference modRef = sourceRefFor(module, module.getSchema());
// TODO: take deviations/features into account
}
for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list
- .module.Submodule submodule : module.nonnullSubmodule()) {
+ .module.Submodule submodule : module.nonnullSubmodule().values()) {
// Submodules go to library, as they are pulled in as needed
librarySources.add(sourceRefFor(submodule, submodule.getSchema()));
}
return resolver.resolveSchemaContext(librarySources, requiredSources);
}
- private String findSchemaName(final List<Datastore> datastores, final QName qname) {
- final Iterator<Datastore> it = datastores.iterator();
+ private String findSchemaName(final Map<DatastoreKey, Datastore> datastores, final QName qname) {
+ final Iterator<Datastore> it = datastores.values().iterator();
final Datastore ds = it.next();
// FIXME: This is ugly, but it is the most compatible thing we can do without knowing the exact requested
}
private static HashSet<String> findModuleSet(final YangLibrary yangLib, final String schemaName) {
- for (Schema schema : yangLib.nonnullSchema()) {
- if (schemaName.equals(schema.getName())) {
- return new HashSet<>(schema.getModuleSet());
- }
+ final Schema schema = yangLib.nonnullSchema().get(new SchemaKey(schemaName));
+ if (schema == null) {
+ throw new IllegalArgumentException("Failed to find moduleSet for " + schemaName);
}
- throw new IllegalArgumentException("Failed to find moduleSet for " + schemaName);
+ return new HashSet<>(schema.getModuleSet());
}
private static void fillModules(final List<SourceReference> librarySources,
final List<SourceReference> requiredSources, final ModuleSet modSet) {
// TODO: take deviations/features into account
- for (ImportOnlyModule mod : modSet.nonnullImportOnlyModule()) {
+ for (ImportOnlyModule mod : modSet.nonnullImportOnlyModule().values()) {
fillSource(librarySources, mod.getName(), ImportOnlyModuleRevisionBuilder.toYangCommon(mod.getRevision()),
mod.getLocation());
- mod.nonnullSubmodule().forEach(sub -> {
+ mod.nonnullSubmodule().values().forEach(sub -> {
fillSource(librarySources, sub.getName(), toYangCommon(sub.getRevision()), sub.getLocation());
});
}
- for (Module mod : modSet.nonnullModule()) {
+ for (Module mod : modSet.nonnullModule().values()) {
fillSource(requiredSources, mod.getName(), toYangCommon(mod.getRevision()), mod.getLocation());
- mod.nonnullSubmodule().forEach(sub -> {
+ mod.nonnullSubmodule().values().forEach(sub -> {
fillSource(librarySources, sub.getName(), toYangCommon(sub.getRevision()), sub.getLocation());
});
}