@Test public void testCopyPrimitive() { Object sourceValue = null; Object targetValue = service.copyPrimitive(sourceValue); assertNull(targetValue); sourceValue = (boolean) true; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Boolean.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(Boolean.TRUE, targetValue); sourceValue = (boolean) false; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Boolean.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(Boolean.FALSE, targetValue); sourceValue = (byte) 1; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Byte.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Byte((byte) 1), targetValue); sourceValue = (byte) 0; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Byte.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Byte((byte) 0), targetValue); sourceValue = (char) 'a'; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Character.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Character('a'), targetValue); sourceValue = (char) 'z'; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Character.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Character('z'), targetValue); sourceValue = Double.MIN_VALUE; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Double.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Double(Double.MIN_VALUE), targetValue); sourceValue = Double.MAX_VALUE; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Double.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Double(Double.MAX_VALUE), targetValue); sourceValue = Float.MIN_VALUE; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Float.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Float(Float.MIN_VALUE), targetValue); sourceValue = Float.MAX_VALUE; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Float.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Float(Float.MAX_VALUE), targetValue); sourceValue = Integer.MIN_VALUE; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Integer.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Integer(Integer.MIN_VALUE), targetValue); sourceValue = Integer.MAX_VALUE; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Integer.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Integer(Integer.MAX_VALUE), targetValue); sourceValue = Long.MIN_VALUE; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Long.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Long(Long.MIN_VALUE), targetValue); sourceValue = Long.MAX_VALUE; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Long.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Long(Long.MAX_VALUE), targetValue); sourceValue = Short.MIN_VALUE; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Short.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Short(Short.MIN_VALUE), targetValue); sourceValue = Short.MAX_VALUE; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertTrue(Short.class.getCanonicalName().equals(targetValue.getClass().getCanonicalName())); assertEquals(new Short(Short.MAX_VALUE), targetValue); sourceValue = new ArrayList<String>(); targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertEquals(sourceValue, targetValue); sourceValue = "foo"; targetValue = service.copyPrimitive(sourceValue); assertNotNull(targetValue); assertEquals("foo", targetValue); }
@Override public Object copyPrimitive(Object sourceValue) { if (sourceValue == null) { return null; } Class<?> clazz = sourceValue.getClass(); if (clazz == null) { return clazz; } else if (boolean.class.getName().equals(clazz.getName())) { return Boolean.valueOf((boolean) sourceValue); } else if (Boolean.class.getName().equals(clazz.getName())) { return Boolean.valueOf((Boolean) sourceValue); } else if (byte.class.getName().equals(clazz.getName())) { return Byte.valueOf((byte) sourceValue); } else if (Byte.class.getName().equals(clazz.getName())) { return Byte.valueOf((Byte) sourceValue); } else if (char.class.getName().equals(clazz.getName())) { return Character.valueOf((char) sourceValue); } else if (Character.class.getName().equals(clazz.getName())) { return Character.valueOf((Character) sourceValue); } else if (double.class.getName().equals(clazz.getName())) { return Double.valueOf((double) sourceValue); } else if (Double.class.getName().equals(clazz.getName())) { return Double.valueOf((Double) sourceValue); } else if (float.class.getName().equals(clazz.getName())) { return Float.valueOf((float) sourceValue); } else if (Float.class.getName().equals(clazz.getName())) { return Float.valueOf((Float) sourceValue); } else if (int.class.getName().equals(clazz.getName())) { return Integer.valueOf((int) sourceValue); } else if (Integer.class.getName().equals(clazz.getName())) { return Integer.valueOf((Integer) sourceValue); } else if (long.class.getName().equals(clazz.getName())) { return Long.valueOf((long) sourceValue); } else if (Long.class.getName().equals(clazz.getName())) { return Long.valueOf((Long) sourceValue); } else if (short.class.getName().equals(clazz.getName())) { return Short.valueOf((short) sourceValue); } else if (Short.class.getName().equals(clazz.getName())) { return Short.valueOf((Short) sourceValue); } return sourceValue; }
DefaultAtlasConversionService implements AtlasConversionService { @Override public Object copyPrimitive(Object sourceValue) { if (sourceValue == null) { return null; } Class<?> clazz = sourceValue.getClass(); if (clazz == null) { return clazz; } else if (boolean.class.getName().equals(clazz.getName())) { return Boolean.valueOf((boolean) sourceValue); } else if (Boolean.class.getName().equals(clazz.getName())) { return Boolean.valueOf((Boolean) sourceValue); } else if (byte.class.getName().equals(clazz.getName())) { return Byte.valueOf((byte) sourceValue); } else if (Byte.class.getName().equals(clazz.getName())) { return Byte.valueOf((Byte) sourceValue); } else if (char.class.getName().equals(clazz.getName())) { return Character.valueOf((char) sourceValue); } else if (Character.class.getName().equals(clazz.getName())) { return Character.valueOf((Character) sourceValue); } else if (double.class.getName().equals(clazz.getName())) { return Double.valueOf((double) sourceValue); } else if (Double.class.getName().equals(clazz.getName())) { return Double.valueOf((Double) sourceValue); } else if (float.class.getName().equals(clazz.getName())) { return Float.valueOf((float) sourceValue); } else if (Float.class.getName().equals(clazz.getName())) { return Float.valueOf((Float) sourceValue); } else if (int.class.getName().equals(clazz.getName())) { return Integer.valueOf((int) sourceValue); } else if (Integer.class.getName().equals(clazz.getName())) { return Integer.valueOf((Integer) sourceValue); } else if (long.class.getName().equals(clazz.getName())) { return Long.valueOf((long) sourceValue); } else if (Long.class.getName().equals(clazz.getName())) { return Long.valueOf((Long) sourceValue); } else if (short.class.getName().equals(clazz.getName())) { return Short.valueOf((short) sourceValue); } else if (Short.class.getName().equals(clazz.getName())) { return Short.valueOf((Short) sourceValue); } return sourceValue; } }
DefaultAtlasConversionService implements AtlasConversionService { @Override public Object copyPrimitive(Object sourceValue) { if (sourceValue == null) { return null; } Class<?> clazz = sourceValue.getClass(); if (clazz == null) { return clazz; } else if (boolean.class.getName().equals(clazz.getName())) { return Boolean.valueOf((boolean) sourceValue); } else if (Boolean.class.getName().equals(clazz.getName())) { return Boolean.valueOf((Boolean) sourceValue); } else if (byte.class.getName().equals(clazz.getName())) { return Byte.valueOf((byte) sourceValue); } else if (Byte.class.getName().equals(clazz.getName())) { return Byte.valueOf((Byte) sourceValue); } else if (char.class.getName().equals(clazz.getName())) { return Character.valueOf((char) sourceValue); } else if (Character.class.getName().equals(clazz.getName())) { return Character.valueOf((Character) sourceValue); } else if (double.class.getName().equals(clazz.getName())) { return Double.valueOf((double) sourceValue); } else if (Double.class.getName().equals(clazz.getName())) { return Double.valueOf((Double) sourceValue); } else if (float.class.getName().equals(clazz.getName())) { return Float.valueOf((float) sourceValue); } else if (Float.class.getName().equals(clazz.getName())) { return Float.valueOf((Float) sourceValue); } else if (int.class.getName().equals(clazz.getName())) { return Integer.valueOf((int) sourceValue); } else if (Integer.class.getName().equals(clazz.getName())) { return Integer.valueOf((Integer) sourceValue); } else if (long.class.getName().equals(clazz.getName())) { return Long.valueOf((long) sourceValue); } else if (Long.class.getName().equals(clazz.getName())) { return Long.valueOf((Long) sourceValue); } else if (short.class.getName().equals(clazz.getName())) { return Short.valueOf((short) sourceValue); } else if (Short.class.getName().equals(clazz.getName())) { return Short.valueOf((Short) sourceValue); } return sourceValue; } private  DefaultAtlasConversionService(); }
DefaultAtlasConversionService implements AtlasConversionService { @Override public Object copyPrimitive(Object sourceValue) { if (sourceValue == null) { return null; } Class<?> clazz = sourceValue.getClass(); if (clazz == null) { return clazz; } else if (boolean.class.getName().equals(clazz.getName())) { return Boolean.valueOf((boolean) sourceValue); } else if (Boolean.class.getName().equals(clazz.getName())) { return Boolean.valueOf((Boolean) sourceValue); } else if (byte.class.getName().equals(clazz.getName())) { return Byte.valueOf((byte) sourceValue); } else if (Byte.class.getName().equals(clazz.getName())) { return Byte.valueOf((Byte) sourceValue); } else if (char.class.getName().equals(clazz.getName())) { return Character.valueOf((char) sourceValue); } else if (Character.class.getName().equals(clazz.getName())) { return Character.valueOf((Character) sourceValue); } else if (double.class.getName().equals(clazz.getName())) { return Double.valueOf((double) sourceValue); } else if (Double.class.getName().equals(clazz.getName())) { return Double.valueOf((Double) sourceValue); } else if (float.class.getName().equals(clazz.getName())) { return Float.valueOf((float) sourceValue); } else if (Float.class.getName().equals(clazz.getName())) { return Float.valueOf((Float) sourceValue); } else if (int.class.getName().equals(clazz.getName())) { return Integer.valueOf((int) sourceValue); } else if (Integer.class.getName().equals(clazz.getName())) { return Integer.valueOf((Integer) sourceValue); } else if (long.class.getName().equals(clazz.getName())) { return Long.valueOf((long) sourceValue); } else if (Long.class.getName().equals(clazz.getName())) { return Long.valueOf((Long) sourceValue); } else if (short.class.getName().equals(clazz.getName())) { return Short.valueOf((short) sourceValue); } else if (Short.class.getName().equals(clazz.getName())) { return Short.valueOf((Short) sourceValue); } return sourceValue; } private  DefaultAtlasConversionService(); static DefaultAtlasConversionService getInstance(); static Set<String> listPrimitiveClassNames(); @Override Optional<AtlasConverter<?>> findMatchingConverter(FieldType source, FieldType target); @Override Optional<AtlasConverter<?>> findMatchingConverter(String sourceClassName, String targetClassName); @Override Object copyPrimitive(Object sourceValue); @Override Object convertType(Object sourceValue, FieldType origSourceType, FieldType targetType); @Override Object convertType(Object sourceValue, String sourceFormat, FieldType targetType, String targetFormat); @Override Object convertType(Object sourceValue, String sourceFormat, Class<?> targetType, String targetFormat); @Override boolean isConvertionAvailableFor(Object sourceValue, Class<?> targetType); @Override Boolean isPrimitive(String className); @Override Boolean isPrimitive(Class<?> clazz); @Override Boolean isPrimitive(FieldType fieldType); @Override Boolean isBoxedPrimitive(Class<?> clazz); @Override Class<?> boxOrUnboxPrimitive(String clazzName); @Override Class<?> boxOrUnboxPrimitive(Class<?> clazz); @Override FieldType fieldTypeFromClass(Class<?> clazz); @Override FieldType fieldTypeFromClass(String className); @Override Class<?> classFromFieldType(FieldType fieldType); @Override Boolean isAssignableFieldType(FieldType source, FieldType target); }
DefaultAtlasConversionService implements AtlasConversionService { @Override public Object copyPrimitive(Object sourceValue) { if (sourceValue == null) { return null; } Class<?> clazz = sourceValue.getClass(); if (clazz == null) { return clazz; } else if (boolean.class.getName().equals(clazz.getName())) { return Boolean.valueOf((boolean) sourceValue); } else if (Boolean.class.getName().equals(clazz.getName())) { return Boolean.valueOf((Boolean) sourceValue); } else if (byte.class.getName().equals(clazz.getName())) { return Byte.valueOf((byte) sourceValue); } else if (Byte.class.getName().equals(clazz.getName())) { return Byte.valueOf((Byte) sourceValue); } else if (char.class.getName().equals(clazz.getName())) { return Character.valueOf((char) sourceValue); } else if (Character.class.getName().equals(clazz.getName())) { return Character.valueOf((Character) sourceValue); } else if (double.class.getName().equals(clazz.getName())) { return Double.valueOf((double) sourceValue); } else if (Double.class.getName().equals(clazz.getName())) { return Double.valueOf((Double) sourceValue); } else if (float.class.getName().equals(clazz.getName())) { return Float.valueOf((float) sourceValue); } else if (Float.class.getName().equals(clazz.getName())) { return Float.valueOf((Float) sourceValue); } else if (int.class.getName().equals(clazz.getName())) { return Integer.valueOf((int) sourceValue); } else if (Integer.class.getName().equals(clazz.getName())) { return Integer.valueOf((Integer) sourceValue); } else if (long.class.getName().equals(clazz.getName())) { return Long.valueOf((long) sourceValue); } else if (Long.class.getName().equals(clazz.getName())) { return Long.valueOf((Long) sourceValue); } else if (short.class.getName().equals(clazz.getName())) { return Short.valueOf((short) sourceValue); } else if (Short.class.getName().equals(clazz.getName())) { return Short.valueOf((Short) sourceValue); } return sourceValue; } private  DefaultAtlasConversionService(); static DefaultAtlasConversionService getInstance(); static Set<String> listPrimitiveClassNames(); @Override Optional<AtlasConverter<?>> findMatchingConverter(FieldType source, FieldType target); @Override Optional<AtlasConverter<?>> findMatchingConverter(String sourceClassName, String targetClassName); @Override Object copyPrimitive(Object sourceValue); @Override Object convertType(Object sourceValue, FieldType origSourceType, FieldType targetType); @Override Object convertType(Object sourceValue, String sourceFormat, FieldType targetType, String targetFormat); @Override Object convertType(Object sourceValue, String sourceFormat, Class<?> targetType, String targetFormat); @Override boolean isConvertionAvailableFor(Object sourceValue, Class<?> targetType); @Override Boolean isPrimitive(String className); @Override Boolean isPrimitive(Class<?> clazz); @Override Boolean isPrimitive(FieldType fieldType); @Override Boolean isBoxedPrimitive(Class<?> clazz); @Override Class<?> boxOrUnboxPrimitive(String clazzName); @Override Class<?> boxOrUnboxPrimitive(Class<?> clazz); @Override FieldType fieldTypeFromClass(Class<?> clazz); @Override FieldType fieldTypeFromClass(String className); @Override Class<?> classFromFieldType(FieldType fieldType); @Override Boolean isAssignableFieldType(FieldType source, FieldType target);  }