From: Robert Varga Date: Mon, 26 Jan 2015 16:13:45 +0000 (+0100) Subject: Cleanup PathArgumentTypes X-Git-Tag: release/lithium~654 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;ds=sidebyside;h=7fd8bdbb1f974e37a18a486f4662ed4e6518406e;p=controller.git Cleanup PathArgumentTypes 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 --- diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/PathArgumentTypes.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/PathArgumentTypes.java index b01beb8c77..dd140ca410 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/PathArgumentTypes.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/PathArgumentTypes.java @@ -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, Byte> CLASS_TO_ENUM_MAP = + private PathArgumentTypes() { + throw new UnsupportedOperationException("Utility class"); + } + + private static final Map, Byte> CLASS_TO_ENUM_MAP = ImmutableMap., 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; }