X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fnode%2Futils%2Fserialization%2FPathArgumentSerializer.java;h=bf10316fd5d8b795154a1caf6d827e1e911d1d5c;hb=7e19c2f4d2695cc4d077a1f5882089d8af923696;hp=4fb676e5189bcb70158cccd1a563f3e54ba36405;hpb=e5baddddcf298e6569aff18e5c4514492980ad9c;p=controller.git diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/PathArgumentSerializer.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/PathArgumentSerializer.java index 4fb676e518..bf10316fd5 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/PathArgumentSerializer.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/PathArgumentSerializer.java @@ -9,28 +9,28 @@ package org.opendaylight.controller.cluster.datastore.node.utils.serialization; import com.google.common.base.Preconditions; - import org.opendaylight.controller.cluster.datastore.node.utils.NodeIdentifierFactory; import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory; import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; - import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; - import static org.opendaylight.controller.cluster.datastore.node.utils.serialization.PathArgumentType.getSerializablePathArgumentType; public class PathArgumentSerializer { private static final String REVISION_ARG = "?revision="; - private static final Map pathArgumentAttributesGetters = new HashMap<>(); + private static final Map, PathArgumentAttributesGetter> pathArgumentAttributesGetters = new HashMap<>(); - public static NormalizedNodeMessages.PathArgument serialize(NormalizedNodeSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument){ + public static NormalizedNodeMessages.PathArgument serialize(QNameSerializationContext context, + YangInstanceIdentifier.PathArgument pathArgument){ Preconditions.checkNotNull(context, "context should not be null"); Preconditions.checkNotNull(pathArgument, "pathArgument should not be null"); @@ -53,7 +53,8 @@ public class PathArgumentSerializer { } - public static YangInstanceIdentifier.PathArgument deSerialize(NormalizedNodeDeSerializationContext context, NormalizedNodeMessages.PathArgument pathArgument){ + public static YangInstanceIdentifier.PathArgument deSerialize(QNameDeSerializationContext context, + NormalizedNodeMessages.PathArgument pathArgument){ Preconditions.checkNotNull(context, "context should not be null"); Preconditions.checkNotNull(pathArgument, "pathArgument should not be null"); @@ -62,18 +63,15 @@ public class PathArgumentSerializer { private static interface PathArgumentAttributesGetter { - Iterable get(NormalizedNodeSerializationContext context, - YangInstanceIdentifier.PathArgument pathArgument); + Iterable get( + QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument); } static { pathArgumentAttributesGetters.put(YangInstanceIdentifier.NodeWithValue.class, new PathArgumentAttributesGetter() { @Override public Iterable get( - NormalizedNodeSerializationContext context, - YangInstanceIdentifier.PathArgument pathArgument) { - List attributes = - new ArrayList<>(); + QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) { YangInstanceIdentifier.NodeWithValue identifier = (YangInstanceIdentifier.NodeWithValue) pathArgument; @@ -81,62 +79,52 @@ public class PathArgumentSerializer { NormalizedNodeMessages.PathArgumentAttribute attribute = buildAttribute(context, null, identifier.getValue()); - attributes.add(attribute); - - return attributes; - + return Arrays.asList(attribute); } }); pathArgumentAttributesGetters.put(YangInstanceIdentifier.NodeIdentifierWithPredicates.class, new PathArgumentAttributesGetter() { @Override public Iterable get( - NormalizedNodeSerializationContext context, - YangInstanceIdentifier.PathArgument pathArgument) { - - List attributes = - new ArrayList<>(); + QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) { YangInstanceIdentifier.NodeIdentifierWithPredicates identifier = (YangInstanceIdentifier.NodeIdentifierWithPredicates) pathArgument; - for (QName key : identifier.getKeyValues().keySet()) { - Object value = identifier.getKeyValues().get(key); + Map keyValues = identifier.getKeyValues(); + List attributes = + new ArrayList<>(keyValues.size()); + for (Entry e : keyValues.entrySet()) { NormalizedNodeMessages.PathArgumentAttribute attribute = - buildAttribute(context, key, value); + buildAttribute(context, e.getKey(), e.getValue()); attributes.add(attribute); - } return attributes; - } }); pathArgumentAttributesGetters.put(YangInstanceIdentifier.AugmentationIdentifier.class, new PathArgumentAttributesGetter() { @Override public Iterable get( - NormalizedNodeSerializationContext context, - YangInstanceIdentifier.PathArgument pathArgument) { - - List attributes = - new ArrayList<>(); + QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) { YangInstanceIdentifier.AugmentationIdentifier identifier = (YangInstanceIdentifier.AugmentationIdentifier) pathArgument; - for (QName key : identifier.getPossibleChildNames()) { + Set possibleChildNames = identifier.getPossibleChildNames(); + List attributes = + new ArrayList<>(possibleChildNames.size()); + for (QName key : possibleChildNames) { Object value = key; NormalizedNodeMessages.PathArgumentAttribute attribute = buildAttribute(context, key, value); attributes.add(attribute); - } return attributes; - } }); @@ -144,14 +132,14 @@ public class PathArgumentSerializer { pathArgumentAttributesGetters.put(YangInstanceIdentifier.NodeIdentifier.class, new PathArgumentAttributesGetter() { @Override public Iterable get( - NormalizedNodeSerializationContext context, - YangInstanceIdentifier.PathArgument pathArgument) { + QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) { return Collections.emptyList(); } }); } - private static NormalizedNodeMessages.PathArgumentAttribute buildAttribute(NormalizedNodeSerializationContext context,QName name, Object value){ + private static NormalizedNodeMessages.PathArgumentAttribute buildAttribute( + QNameSerializationContext context, QName name, Object value) { NormalizedNodeMessages.PathArgumentAttribute.Builder builder = NormalizedNodeMessages.PathArgumentAttribute.newBuilder(); @@ -162,8 +150,9 @@ public class PathArgumentSerializer { } - private static NormalizedNodeMessages.QName.Builder encodeQName(NormalizedNodeSerializationContext context, QName qName){ - if(qName == null){ + private static NormalizedNodeMessages.QName.Builder encodeQName(QNameSerializationContext context, + QName qName) { + if(qName == null) { return NormalizedNodeMessages.QName.getDefaultInstance().toBuilder(); } NormalizedNodeMessages.QName.Builder qNameBuilder = @@ -179,15 +168,13 @@ public class PathArgumentSerializer { } private static Iterable getPathArgumentAttributes( - NormalizedNodeSerializationContext context, - YangInstanceIdentifier.PathArgument pathArgument) { + QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) { return pathArgumentAttributesGetters.get(pathArgument.getClass()).get(context, pathArgument); - } - private static String qNameToString(NormalizedNodeDeSerializationContext context, + private static String qNameToString(QNameDeSerializationContext context, NormalizedNodeMessages.QName qName){ // If this serializer is used qName cannot be null (see encodeQName) // adding null check only in case someone tried to deSerialize a protocol buffer node @@ -219,8 +206,7 @@ public class PathArgumentSerializer { * @return MD-SAL PathArgument */ private static YangInstanceIdentifier.PathArgument parsePathArgument( - NormalizedNodeDeSerializationContext context, - NormalizedNodeMessages.PathArgument pathArgument) { + QNameDeSerializationContext context, NormalizedNodeMessages.PathArgument pathArgument) { switch(PathArgumentType.values()[pathArgument.getIntType()]){ case NODE_IDENTIFIER_WITH_VALUE : { @@ -264,8 +250,8 @@ public class PathArgumentSerializer { } private static Map toAttributesMap( - NormalizedNodeDeSerializationContext context, - List attributesList) { + QNameDeSerializationContext context, + List attributesList) { Map map; if(attributesList.size() == 1) { @@ -287,7 +273,8 @@ public class PathArgumentSerializer { return map; } - private static Object parseAttribute(NormalizedNodeDeSerializationContext context, NormalizedNodeMessages.PathArgumentAttribute attribute){ + private static Object parseAttribute(QNameDeSerializationContext context, + NormalizedNodeMessages.PathArgumentAttribute attribute){ return ValueSerializer.deSerialize(context, attribute); }