X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-dom-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fdom%2Fcodec%2Fimpl%2FListNodeCodecContext.java;h=e69b6e9281c5c45750dfa1b02b22564589a15f99;hb=172f47ef9f3c164359da032e5768ebb12f3feb14;hp=7380700b8525eb7032b11038560bc6c39d358f4c;hpb=259957ffe47414cc197f4a819361e8a6dcf50b19;p=mdsal.git diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ListNodeCodecContext.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ListNodeCodecContext.java index 7380700b85..e69b6e9281 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ListNodeCodecContext.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ListNodeCodecContext.java @@ -8,73 +8,65 @@ package org.opendaylight.mdsal.binding.dom.codec.impl; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.List; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.mdsal.binding.runtime.api.ListRuntimeType; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; -import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; -class ListNodeCodecContext extends DataObjectCodecContext { - ListNodeCodecContext(final DataContainerCodecPrototype prototype) { +class ListNodeCodecContext extends DataObjectCodecContext { + ListNodeCodecContext(final DataContainerCodecPrototype prototype) { super(prototype); } - ListNodeCodecContext(final DataContainerCodecPrototype prototype, final Method keyMethod) { + ListNodeCodecContext(final DataContainerCodecPrototype prototype, + final Method keyMethod) { super(prototype, keyMethod); } @Override - public D deserialize(final NormalizedNode node) { + public D deserialize(final NormalizedNode node) { if (node instanceof MapEntryNode) { - return fromMapEntry((MapEntryNode) node); + return createBindingProxy((MapEntryNode) node); } else if (node instanceof UnkeyedListEntryNode) { - return fromUnkeyedListEntry((UnkeyedListEntryNode) node); + return createBindingProxy((UnkeyedListEntryNode) node); } else { throw new IllegalStateException("Unsupported data type " + node.getClass()); } } @Override - protected Object deserializeObject(final NormalizedNode node) { + protected Object deserializeObject(final NormalizedNode node) { if (node instanceof MapNode) { return fromMap((MapNode) node); } else if (node instanceof MapEntryNode) { - return fromMapEntry((MapEntryNode) node); + return createBindingProxy((MapEntryNode) node); } else if (node instanceof UnkeyedListNode) { return fromUnkeyedList((UnkeyedListNode) node); } else if (node instanceof UnkeyedListEntryNode) { - return fromUnkeyedListEntry((UnkeyedListEntryNode) node); + return createBindingProxy((UnkeyedListEntryNode) node); } else { throw new IllegalStateException("Unsupported data type " + node.getClass()); } } - private List fromMap(final MapNode nodes) { - List ret = new ArrayList<>(nodes.getValue().size()); - for (MapEntryNode node : nodes.getValue()) { - ret.add(fromMapEntry(node)); - } - return ret; - } - - private D fromMapEntry(final MapEntryNode node) { - return createBindingProxy(node); + @NonNull Object fromMap(final MapNode map, final int size) { + return LazyBindingList.create(this, size, map.body()); } - private D fromUnkeyedListEntry(final UnkeyedListEntryNode node) { - return createBindingProxy(node); + private Object fromMap(final MapNode map) { + final int size; + // This should never happen, but we do need to ensure users never see an empty Map + return (size = map.size()) == 0 ? null : fromMap(map, size); } - private List fromUnkeyedList(final UnkeyedListNode nodes) { - // FIXME: Could be this lazy transformed list? - List ret = new ArrayList<>(nodes.getValue().size()); - for (UnkeyedListEntryNode node : nodes.getValue()) { - ret.add(fromUnkeyedListEntry(node)); - } - return ret; + private List fromUnkeyedList(final UnkeyedListNode node) { + final int size; + // This should never happen, but we do need to ensure users never see an empty List + return (size = node.size()) == 0 ? null : LazyBindingList.create(this, size, node.body()); } -} \ No newline at end of file +}