DataObjectUtil { static DataType getType(Object object) { if (object instanceof Byte) { return DataType.BYTE; } else if (object instanceof Boolean) { return DataType.BOOL; } else if (object instanceof Short) { return DataType.INT16; } else if (object instanceof Integer) { return DataType.INT32; } else if (object instanceof Long) { return DataType.INT64; } else if (object instanceof Float) { return DataType.FLOAT; } else if (object instanceof Double) { return DataType.DOUBLE; } else if (object instanceof String) { return DataType.STRING; } else if (object instanceof Byte[] || object instanceof byte[]) { return DataType.BYTE_ARRAY; } else if (object instanceof Boolean[] || object instanceof boolean[]) { return DataType.BOOL_ARRAY; } else if (object instanceof Short[] || object instanceof short[]) { return DataType.INT16_ARRAY; } else if (object instanceof Integer[] || object instanceof int[]) { return DataType.INT32_ARRAY; } else if (object instanceof Long[] || object instanceof long[]) { return DataType.INT64_ARRAY; } else if (object instanceof Float[] || object instanceof float[]) { return DataType.FLOAT_ARRAY; } else if (object instanceof Double[] || object instanceof double[]) { return DataType.DOUBLE_ARRAY; } else if (object instanceof String[]) { return DataType.STRING_ARRAY; } else if (object instanceof DataObject) { return DataType.DataObject; } else { return DataType.NONE; } }    }
@Test public void testGetType() throws Exception { Assert.assertEquals(DataType.BYTE, DataObjectUtil.getType(BYTE_DATA)); Assert.assertEquals(DataType.BOOL, DataObjectUtil.getType(BOOLEAN_DATA)); Assert.assertEquals(DataType.INT16, DataObjectUtil.getType(SHORT_DATA)); Assert.assertEquals(DataType.INT32, DataObjectUtil.getType(INT_DATA)); Assert.assertEquals(DataType.INT64, DataObjectUtil.getType(LONG_DATA)); Assert.assertEquals(DataType.FLOAT, DataObjectUtil.getType(FLOAT_DATA)); Assert.assertEquals(DataType.DOUBLE, DataObjectUtil.getType(DOUBLE_DATA)); Assert.assertEquals(DataType.STRING, DataObjectUtil.getType(STRING_DATA)); Assert.assertEquals(DataType.BYTE_ARRAY, DataObjectUtil.getType(BYTE_OBJECT_ARRAY_DATA)); Assert.assertEquals(DataType.BOOL_ARRAY, DataObjectUtil.getType(BOOLEAN_OBJECT_ARRAY_DATA)); Assert.assertEquals(DataType.INT16_ARRAY, DataObjectUtil.getType(SHORT_OBJECT_ARRAY_DATA)); Assert.assertEquals(DataType.INT32_ARRAY, DataObjectUtil.getType(INT_OBJECT_ARRAY_DATA)); Assert.assertEquals(DataType.INT64_ARRAY, DataObjectUtil.getType(LONG_OBJECT_ARRAY_DATA)); Assert.assertEquals(DataType.FLOAT_ARRAY, DataObjectUtil.getType(FLOAT_OBJECT_ARRAY_DATA)); Assert.assertEquals(DataType.DOUBLE_ARRAY, DataObjectUtil.getType(DOUBLE_OBJECT_ARRAY_DATA)); Assert.assertEquals(DataType.STRING_ARRAY, DataObjectUtil.getType(STRING_OBJECT_ARRAY_DATA)); Assert.assertEquals(DataType.BYTE_ARRAY, DataObjectUtil.getType(BYTE_ARRAY_DATA)); Assert.assertEquals(DataType.BOOL_ARRAY, DataObjectUtil.getType(BOOLEAN_ARRAY_DATA)); Assert.assertEquals(DataType.INT16_ARRAY, DataObjectUtil.getType(SHORT_ARRAY_DATA)); Assert.assertEquals(DataType.INT32_ARRAY, DataObjectUtil.getType(INT_ARRAY_DATA)); Assert.assertEquals(DataType.INT64_ARRAY, DataObjectUtil.getType(LONG_ARRAY_DATA)); Assert.assertEquals(DataType.FLOAT_ARRAY, DataObjectUtil.getType(FLOAT_ARRAY_DATA)); Assert.assertEquals(DataType.DOUBLE_ARRAY, DataObjectUtil.getType(DOUBLE_ARRAY_DATA)); }