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%2FPathArgumentType.java;h=58a09ae88599204a4414f9844db1bb57e032be32;hb=7e19c2f4d2695cc4d077a1f5882089d8af923696;hp=20009d8347564c59d6f98ff537324938f6168a87;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/PathArgumentType.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/PathArgumentType.java index 20009d8347..58a09ae885 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/PathArgumentType.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/PathArgumentType.java @@ -8,8 +8,9 @@ package org.opendaylight.controller.cluster.datastore.node.utils.serialization; -import com.google.common.base.Preconditions; +import java.util.Map; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import com.google.common.collect.ImmutableMap; public enum PathArgumentType { AUGMENTATION_IDENTIFIER, @@ -17,19 +18,21 @@ public enum PathArgumentType { NODE_IDENTIFIER_WITH_VALUE, NODE_IDENTIFIER_WITH_PREDICATES; + private static Map, PathArgumentType> CLASS_TO_ENUM_MAP = + ImmutableMap., PathArgumentType>builder(). + put(YangInstanceIdentifier.AugmentationIdentifier.class, AUGMENTATION_IDENTIFIER). + put(YangInstanceIdentifier.NodeIdentifier.class, NODE_IDENTIFIER). + put(YangInstanceIdentifier.NodeIdentifierWithPredicates.class, NODE_IDENTIFIER_WITH_PREDICATES). + put(YangInstanceIdentifier.NodeWithValue.class, NODE_IDENTIFIER_WITH_VALUE).build(); + public static int getSerializablePathArgumentType(YangInstanceIdentifier.PathArgument pathArgument){ - Preconditions.checkNotNull(pathArgument, "pathArgument should not be null"); - - if(pathArgument instanceof YangInstanceIdentifier.AugmentationIdentifier){ - return AUGMENTATION_IDENTIFIER.ordinal(); - } else if(pathArgument instanceof YangInstanceIdentifier.NodeIdentifier){ - return NODE_IDENTIFIER.ordinal(); - } else if(pathArgument instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates){ - return NODE_IDENTIFIER_WITH_PREDICATES.ordinal(); - } else if(pathArgument instanceof YangInstanceIdentifier.NodeWithValue){ - return NODE_IDENTIFIER_WITH_VALUE.ordinal(); + + PathArgumentType type = CLASS_TO_ENUM_MAP.get(pathArgument.getClass()); + if(type == null) { + throw new IllegalArgumentException("Unknown type of PathArgument = " + pathArgument); } - throw new IllegalArgumentException("Unknown type of PathArgument = " + pathArgument.toString()); + + return type.ordinal(); } }