2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.datastore.node.utils.serialization;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.ImmutableMap;
13 import com.google.common.collect.ImmutableMap.Builder;
14 import java.math.BigDecimal;
15 import java.math.BigInteger;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 public enum ValueType {
35 private static final Map<Class<?>, ValueType> TYPES;
38 final Builder<Class<?>, ValueType> b = ImmutableMap.builder();
40 b.put(String.class, STRING_TYPE);
41 b.put(Byte.class, BYTE_TYPE);
42 b.put(Integer.class, INT_TYPE);
43 b.put(Long.class, LONG_TYPE);
44 b.put(Boolean.class, BOOL_TYPE);
45 b.put(QName.class, QNAME_TYPE);
46 b.put(YangInstanceIdentifier.class, YANG_IDENTIFIER_TYPE);
47 b.put(Short.class,SHORT_TYPE);
48 b.put(BigInteger.class, BIG_INTEGER_TYPE);
49 b.put(BigDecimal.class, BIG_DECIMAL_TYPE);
50 b.put(byte[].class, BINARY_TYPE);
55 public static final ValueType getSerializableType(Object node) {
56 Preconditions.checkNotNull(node, "node should not be null");
58 final ValueType type = TYPES.get(node.getClass());
62 if (node instanceof Set) {
66 throw new IllegalArgumentException("Unknown value type " + node.getClass().getSimpleName());