From 78b382981d681f269b5a93ce51132b453024bfba Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 31 Aug 2014 02:21:28 +0200 Subject: [PATCH] BUG-1440: remove open-coded Multimap The code is completely equivalent with what Guava's Multimap provides, so let's just use that. Change-Id: I8f0a22a89c4c31a62f16ebd970f940cfc04af2ff Signed-off-by: Robert Varga --- .../gson/CompositeNodeDataWithSchema.java | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/CompositeNodeDataWithSchema.java b/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/CompositeNodeDataWithSchema.java index 4c38c3120c..48f063e7f4 100644 --- a/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/CompositeNodeDataWithSchema.java +++ b/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/CompositeNodeDataWithSchema.java @@ -9,16 +9,16 @@ package org.opendaylight.yangtools.yang.data.codec.gson; import com.google.common.base.Function; import com.google.common.base.Preconditions; +import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Deque; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.Map.Entry; import javax.annotation.Nonnull; @@ -51,7 +51,7 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { /** * nodes which were added to schema via augmentation and are present in data input */ - private final Map> augmentationsToChild = new LinkedHashMap<>(); + private final Multimap augmentationsToChild = ArrayListMultimap.create(); /** * remaining data nodes (which aren't added via augment). Every of one them should have the same QName. @@ -89,7 +89,7 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { } // looking for existing choice - final List childNodes; + final Collection childNodes; if (augSchema != null) { childNodes = augmentationsToChild.get(augSchema); } else { @@ -121,7 +121,7 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { augSchema = findCorrespondingAugment(getSchema(), schema); } if (augSchema != null) { - addChildToAugmentation(augSchema, newChild); + augmentationsToChild.put(augSchema, newChild); } else { addChild(newChild); } @@ -130,16 +130,7 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { return null; } - private void addChildToAugmentation(final AugmentationSchema augSchema, final AbstractNodeDataWithSchema newChild) { - List childsInAugment = augmentationsToChild.get(augSchema); - if (childsInAugment == null) { - childsInAugment = new ArrayList<>(); - augmentationsToChild.put(augSchema, childsInAugment); - } - childsInAugment.add(newChild); - } - - private CaseNodeDataWithSchema findChoice(final List childNodes, final DataSchemaNode choiceCandidate, + private CaseNodeDataWithSchema findChoice(final Collection childNodes, final DataSchemaNode choiceCandidate, final DataSchemaNode caseCandidate) { if (childNodes != null) { for (AbstractNodeDataWithSchema nodeDataWithSchema : childNodes) { @@ -176,7 +167,7 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { void addCompositeChild(final CompositeNodeDataWithSchema newChild) { AugmentationSchema augSchema = findCorrespondingAugment(getSchema(), newChild.getSchema()); if (augSchema != null) { - addChildToAugmentation(augSchema, newChild); + augmentationsToChild.put(augSchema, newChild); } else { addChild(newChild); } @@ -220,8 +211,8 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema { for (AbstractNodeDataWithSchema child : children) { child.write(writer); } - for (Entry> augmentationToChild : augmentationsToChild.entrySet()) { - final List childsFromAgumentation = augmentationToChild.getValue(); + for (Entry> augmentationToChild : augmentationsToChild.asMap().entrySet()) { + final Collection childsFromAgumentation = augmentationToChild.getValue(); if (!childsFromAgumentation.isEmpty()) { writer.startAugmentationNode(toAugmentationIdentifier(augmentationToChild.getKey())); -- 2.36.6