Cleanup PathArgumentTypes 04/14504/4
authorRobert Varga <rovarga@cisco.com>
Mon, 26 Jan 2015 16:13:45 +0000 (17:13 +0100)
committerRobert Varga <rovarga@cisco.com>
Wed, 28 Jan 2015 16:18:59 +0000 (17:18 +0100)
PathArgumentTypes is a utility class, it should be final with a private
constructor. Also make sure the internal map is truly constant.

Change-Id: I1cbbcac5c86daa64fc1fb79a7282fdd29b6566d7
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/PathArgumentTypes.java

index b01beb8c779b5b80907a0afcf51cc04f58c54d60..dd140ca410156d028175243dbd66fba67e339794 100644 (file)
@@ -8,31 +8,31 @@
 
 package org.opendaylight.controller.cluster.datastore.node.utils.stream;
 
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-
 import java.util.Map;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
-public class PathArgumentTypes {
+final class PathArgumentTypes {
     public static final byte AUGMENTATION_IDENTIFIER = 1;
     public static final byte NODE_IDENTIFIER = 2;
     public static final byte NODE_IDENTIFIER_WITH_VALUE = 3;
     public static final byte NODE_IDENTIFIER_WITH_PREDICATES = 4;
 
-    private static Map<Class<?>, Byte> CLASS_TO_ENUM_MAP =
+    private PathArgumentTypes() {
+        throw new UnsupportedOperationException("Utility class");
+    }
+
+    private static final Map<Class<?>, Byte> CLASS_TO_ENUM_MAP =
             ImmutableMap.<Class<?>, Byte>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 byte getSerializablePathArgumentType(YangInstanceIdentifier.PathArgument pathArgument){
-
-        Byte type = CLASS_TO_ENUM_MAP.get(pathArgument.getClass());
-        if(type == null) {
-            throw new IllegalArgumentException("Unknown type of PathArgument = " + pathArgument);
-        }
-
+    public static byte getSerializablePathArgumentType(YangInstanceIdentifier.PathArgument pathArgument) {
+        final Byte type = CLASS_TO_ENUM_MAP.get(pathArgument.getClass());
+        Preconditions.checkArgument(type != null, "Unknown type of PathArgument = %s", pathArgument);
         return type;
     }