/** * Test method for * {@link com.impetus.kundera.property.accessor.BooleanAccessor#fromString(java.lang.Class, java.lang.String)} * . */ @Test public void testFromString() { Assert.assertNull(accessor.fromString(Boolean.class, null)); Assert.assertTrue(accessor.fromString(Boolean.class, "true")); Assert.assertFalse(accessor.fromString(Boolean.class, "false")); }
public static Object fromDate(Class<?> targetClass, Class<?> sourceClass, Object o) { if (!targetClass.equals(sourceClass)) { PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(sourceClass); byte[] b = accessor.toBytes(o); accessor = PropertyAccessorFactory.getPropertyAccessor(targetClass); return accessor.fromBytes(targetClass, b); } return o; }
/** * Test method for {@link com.impetus.kundera.property.accessor.BigIntegerAccessor#toBytes(java.lang.Object)}. */ @Test public void testToBytes() { Assert.assertNull(accessor.toString(null)); BigInteger v1 = new BigInteger("1111111111"); byte[] b = accessor.toBytes(v1); BigInteger v2 = accessor.fromBytes(BigInteger.class, b); Assert.assertEquals(v1, v2); }
public static Object fromSourceToTargetClass(Class<?> targetClass, Class<?> sourceClass, Object o) { if (!targetClass.equals(sourceClass)) { PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(sourceClass); String s = accessor.toString(o); accessor = PropertyAccessorFactory.getPropertyAccessor(targetClass); return accessor.fromString(targetClass, s); } return o; }
value = PropertyAccessorFactory.getPropertyAccessor(clazz).fromString(clazz, value.toString()); return PropertyAccessorFactory.getPropertyAccessor(clazz).toBytes(value);
String columnName = PropertyAccessorFactory.STRING.fromBytes(String.class, nameInByte); && key.getClass().isAssignableFrom(String.class) && !key.getClass().equals(javaType)) key = PropertyAccessorFactory.getPropertyAccessor(javaType).fromString(javaType, key.toString());
public static final byte[] toBytes(Object o, Class c) { PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(c); return accessor.toBytes(o); }
public static Object getObject(Class clazz, byte[] b) { return PropertyAccessorFactory.getPropertyAccessor(clazz).fromBytes(clazz, b); }
public static String getString(Object o) { return o != null ? PropertyAccessorFactory.getPropertyAccessor(o.getClass()).toString(o) : null; }
/** * Test method for * {@link com.impetus.kundera.property.accessor.BooleanAccessor#getCopy(java.lang.Object)} * . */ @Test public void testGetCopy() { Assert.assertNull(accessor.getCopy(null)); Assert.assertTrue(accessor.getCopy(new Boolean(true))); Assert.assertFalse(accessor.getCopy(new Boolean(false))); }
value = PropertyAccessorFactory.getPropertyAccessor(clazz).fromString(clazz, value.toString()); return PropertyAccessorFactory.getPropertyAccessor(clazz).toBytes(value);
public static final byte[] toBytes(Object o, Field f) { PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(f); return accessor.toBytes(o); }
/** * Test method for * {@link com.impetus.kundera.property.accessor.BooleanAccessor#toString(java.lang.Object)} * . */ @Test public void testToStringObject() { Assert.assertNull(accessor.toString(null)); Assert.assertEquals("true", accessor.toString(new Boolean(true))); Assert.assertEquals("false", accessor.toString(new Boolean(false))); }
/** * Test method for {@link com.impetus.kundera.property.accessor.BigIntegerAccessor#getCopy(java.lang.Object)}. */ @Test public void testGetCopy() { Assert.assertNull(accessor.getCopy(null)); BigInteger v1 = new BigInteger("1111111111"); BigInteger v2 = accessor.getCopy(v1); Assert.assertEquals(v1, v2); }
@Test public void testFromBytes() { byte[] bytes = new byte[] {}; Assert.assertNull(accessor.fromBytes(LongAccessor.class, bytes)); Long l = 49L; bytes = accessor.toBytes(l); Assert.assertEquals(l, accessor.fromBytes(LongAccessor.class, bytes)); l = 12l; bytes = accessor.toBytes(l); Assert.assertEquals(l, (Long) accessor.fromBytes(LongAccessor.class, bytes)); }
/** * Sets a byte-array onto a field. * * @param target * the target * @param field * the field * @param fieldVal * the field value * * @throws PropertyAccessException * the property access exception */ public static void set(Object target, Field field, String fieldVal) { PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(field); Object value = accessor.fromString(target.getClass(), fieldVal); set(target, field, value); }
value = PropertyAccessorFactory.getPropertyAccessor(clazz).fromString(clazz, value.toString()); .toBytes(value)));
/** * Test method for {@link com.impetus.kundera.property.accessor.BigDecimalAccessor#toBytes(java.lang.Object)}. */ @Test public void testToBytes() { Assert.assertNull(accessor.toString(null)); BigDecimal v1 = new BigDecimal(1111111111); byte[] b = accessor.toBytes(v1); BigDecimal v2 = accessor.fromBytes(BigDecimal.class, b); Assert.assertEquals(v1, v2); }
public static byte[] getBytes(Object o) { return PropertyAccessorFactory.getPropertyAccessor(o.getClass()).toBytes(o); }