X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fnode%2Futils%2Fstream%2FValueTypes.java;h=8eac59a96b51ec8b1ab2fba25cd3f0f1ffbdc4d7;hb=fba327c801062a6e802f212a0e8b6efee2f6a90e;hp=e75a454d394294795c633a1d57d83ccc5661ce98;hpb=3f153e5fa694fe4147e72e615edbb5c263e5a394;p=controller.git 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..8eac59a96b 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,59 +5,32 @@ * 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 com.google.common.base.Preconditions; -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 { - public static final byte SHORT_TYPE = 1; - public static final byte BYTE_TYPE = 2; - public static final byte INT_TYPE = 3; - public static final byte LONG_TYPE = 4; - public static final byte BOOL_TYPE = 5; - public static final byte QNAME_TYPE = 6; - public static final byte BITS_TYPE = 7; - public static final byte YANG_IDENTIFIER_TYPE = 8; - public static final byte STRING_TYPE = 9; - public static final byte BIG_INTEGER_TYPE = 10; - public static final byte BIG_DECIMAL_TYPE = 11; - public static final byte BINARY_TYPE = 12; - - private static Map, Byte> types = new HashMap<>(); - - 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)); - } - - public static final byte getSerializableType(Object node){ - Preconditions.checkNotNull(node, "node should not be null"); - - Byte type = types.get(node.getClass()); - if(type != null) { - return type; - } else if(node instanceof Set){ - return BITS_TYPE; - } - - throw new IllegalArgumentException("Unknown value type " + node.getClass().getSimpleName()); +final class ValueTypes { + // The String length threshold beyond which a String should be encoded as bytes + static final int STRING_BYTES_LENGTH_THRESHOLD = Short.MAX_VALUE / 4; + + static final byte SHORT_TYPE = 1; + static final byte BYTE_TYPE = 2; + static final byte INT_TYPE = 3; + static final byte LONG_TYPE = 4; + static final byte BOOL_TYPE = 5; + static final byte QNAME_TYPE = 6; + static final byte BITS_TYPE = 7; + static final byte YANG_IDENTIFIER_TYPE = 8; + static final byte STRING_TYPE = 9; + static final byte BIG_INTEGER_TYPE = 10; + static final byte BIG_DECIMAL_TYPE = 11; + static final byte BINARY_TYPE = 12; + // Leaf nodes no longer allow null values. The "empty" type is now represented as + // org.opendaylight.yangtools.yang.common.Empty. This is kept for backwards compatibility. + @Deprecated + static final byte NULL_TYPE = 13; + static final byte STRING_BYTES_TYPE = 14; + static final byte EMPTY_TYPE = 15; + + private ValueTypes() { + throw new UnsupportedOperationException("Utility class"); } }