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,
NODE_IDENTIFIER_WITH_VALUE,
NODE_IDENTIFIER_WITH_PREDICATES;
+ private static Map<Class<?>, PathArgumentType> CLASS_TO_ENUM_MAP =
+ ImmutableMap.<Class<?>, 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();
}
}