From: Robert Varga Date: Wed, 28 Aug 2019 12:56:04 +0000 (+0200) Subject: Cleanup ValueTypes lookup X-Git-Tag: release/magnesium~114 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=b08cec09b7113965fbda5ef1757ca23d7588e5cc;hp=76b19a3323d73115a126f17bd17d893c5ebdba83 Cleanup ValueTypes lookup Change type of TYPES to ImmutableMap, so we are binding to a concrete class when looking up. Also clean up initialization to follow fluent builder pattern. Finally inline requireNonNull() call into the invocation, so that its return value is not wasted. Change-Id: I4487bd43232131ca548441f4c8901a8c5dc60efa 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/ValueTypes.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java index 51ff8d3500..2fd8055c15 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 @@ -5,15 +5,13 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.datastore.node.utils.stream; +import static java.util.Objects.requireNonNull; + import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.Map; -import java.util.Objects; import java.util.Set; import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.common.QName; @@ -42,34 +40,26 @@ final class ValueTypes { public static final byte STRING_BYTES_TYPE = 14; public static final byte EMPTY_TYPE = 15; - private static final Map, Byte> TYPES; - - static { - final Builder, Byte> b = ImmutableMap.builder(); - - b.put(String.class, STRING_TYPE); - b.put(Byte.class, BYTE_TYPE); - b.put(Integer.class, INT_TYPE); - b.put(Long.class, LONG_TYPE); - b.put(Boolean.class, BOOL_TYPE); - b.put(QName.class, QNAME_TYPE); - b.put(Short.class, SHORT_TYPE); - b.put(BigInteger.class, BIG_INTEGER_TYPE); - b.put(BigDecimal.class, BIG_DECIMAL_TYPE); - b.put(byte[].class, BINARY_TYPE); - b.put(Empty.class, EMPTY_TYPE); - - TYPES = b.build(); - } + private static final ImmutableMap, Byte> TYPES = ImmutableMap., Byte>builder() + .put(String.class, STRING_TYPE) + .put(Byte.class, BYTE_TYPE) + .put(Integer.class, INT_TYPE) + .put(Long.class, LONG_TYPE) + .put(Boolean.class, BOOL_TYPE) + .put(QName.class, QNAME_TYPE) + .put(Short.class, SHORT_TYPE) + .put(BigInteger.class, BIG_INTEGER_TYPE) + .put(BigDecimal.class, BIG_DECIMAL_TYPE) + .put(byte[].class, BINARY_TYPE) + .put(Empty.class, EMPTY_TYPE) + .build(); private ValueTypes() { throw new UnsupportedOperationException("Utility class"); } - public static byte getSerializableType(Object node) { - Objects.requireNonNull(node); - - final Byte type = TYPES.get(node.getClass()); + static byte getSerializableType(final Object node) { + final Byte type = TYPES.get(requireNonNull(node).getClass()); if (type != null) { if (type == STRING_TYPE && ((String) node).length() >= STRING_BYTES_LENGTH_THRESHOLD) { return STRING_BYTES_TYPE;