X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fnode%2Futils%2Fstream%2FValueTypes.java;h=f107ce75a708f87d3e0e5ab620bb218551e8490a;hp=e75a454d394294795c633a1d57d83ccc5661ce98;hb=33179a62d9ca17f91af80c3ebb07ad1c1ae66704;hpb=85a4118a6fe51d8571a1e7bb398d954e4ceddd33 diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java index e75a454d39..f107ce75a7 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java @@ -8,16 +8,16 @@ package org.opendaylight.controller.cluster.datastore.node.utils.stream; -import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.HashMap; import java.util.Map; import java.util.Set; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -public class ValueTypes { +final class ValueTypes { public static final byte SHORT_TYPE = 1; public static final byte BYTE_TYPE = 2; public static final byte INT_TYPE = 3; @@ -30,34 +30,49 @@ public class ValueTypes { public static final byte BIG_INTEGER_TYPE = 10; public static final byte BIG_DECIMAL_TYPE = 11; public static final byte BINARY_TYPE = 12; + public static final byte NULL_TYPE = 13; - private static Map, Byte> types = new HashMap<>(); + private static final Map, Byte> TYPES; static { - types.put(String.class, Byte.valueOf(STRING_TYPE)); - types.put(Byte.class, Byte.valueOf(BYTE_TYPE)); - types.put(Integer.class, Byte.valueOf(INT_TYPE)); - types.put(Long.class, Byte.valueOf(LONG_TYPE)); - types.put(Boolean.class, Byte.valueOf(BOOL_TYPE)); - types.put(QName.class, Byte.valueOf(QNAME_TYPE)); - types.put(Set.class, Byte.valueOf(BITS_TYPE)); - types.put(YangInstanceIdentifier.class, Byte.valueOf(YANG_IDENTIFIER_TYPE)); - types.put(Short.class, Byte.valueOf(SHORT_TYPE)); - types.put(BigInteger.class, Byte.valueOf(BIG_INTEGER_TYPE)); - types.put(BigDecimal.class, Byte.valueOf(BIG_DECIMAL_TYPE)); - types.put(byte[].class, Byte.valueOf(BINARY_TYPE)); + final Builder, Byte> b = ImmutableMap.builder(); + + b.put(String.class, Byte.valueOf(STRING_TYPE)); + b.put(Byte.class, Byte.valueOf(BYTE_TYPE)); + b.put(Integer.class, Byte.valueOf(INT_TYPE)); + b.put(Long.class, Byte.valueOf(LONG_TYPE)); + b.put(Boolean.class, Byte.valueOf(BOOL_TYPE)); + b.put(QName.class, Byte.valueOf(QNAME_TYPE)); + b.put(Short.class, Byte.valueOf(SHORT_TYPE)); + b.put(BigInteger.class, Byte.valueOf(BIG_INTEGER_TYPE)); + b.put(BigDecimal.class, Byte.valueOf(BIG_DECIMAL_TYPE)); + b.put(byte[].class, Byte.valueOf(BINARY_TYPE)); + + TYPES = b.build(); } - public static final byte getSerializableType(Object node){ - Preconditions.checkNotNull(node, "node should not be null"); + private ValueTypes() { + throw new UnsupportedOperationException("Utility class"); + } + + public static final byte getSerializableType(Object node) { + if(node == null){ + return NULL_TYPE; + } - Byte type = types.get(node.getClass()); - if(type != null) { + final Byte type = TYPES.get(node.getClass()); + if (type != null) { return type; - } else if(node instanceof Set){ + } + + if (node instanceof Set) { return BITS_TYPE; } + if (node instanceof YangInstanceIdentifier) { + return YANG_IDENTIFIER_TYPE; + } + throw new IllegalArgumentException("Unknown value type " + node.getClass().getSimpleName()); } }