/** * Method for instantiating an object from another object. * * @param in The input object. * @return The output object. */ public O transform(I in) { return transform(null, in); }
/** * Method for instantiating an object from another object. * * @param in The input object. * @return The output object. */ public O transform(I in) { return transform(null, in); }
/** * Method for instantiating an object from another object. * * @param in The input object. * @return The output object. */ public O transform(I in) { return transform(null, in); }
/** * Transforms the specified object into an instance of this class. * * @param o The object to transform. * @return The transformed object. */ @SuppressWarnings({"unchecked","rawtypes"}) public T transformFrom(Object o) { Transform t = getFromTransform(o.getClass()); return (T)(t == null ? null : t.transform(o)); }
/** * Transforms the specified object into an instance of this class. * * @param o The object to transform. * @param c The class * @return The transformed object. */ @SuppressWarnings({"unchecked","rawtypes"}) public <O> O transformTo(Object o, Class<O> c) { Transform t = getToTransform(c); return (O)(t == null ? null : t.transform(o)); }
/** * Transforms the specified object into an instance of this class. * * @param o The object to transform. * @return The transformed object. */ @SuppressWarnings({"unchecked","rawtypes"}) public T transformFrom(Object o) { Transform t = getFromTransform(o.getClass()); return (T)(t == null ? null : t.transform(o)); }
/** * Transforms the specified object into an instance of this class. * * @param o The object to transform. * @param c The class * @return The transformed object. */ @SuppressWarnings({"unchecked","rawtypes"}) public <O> O transformTo(Object o, Class<O> c) { Transform t = getToTransform(c); return (O)(t == null ? null : t.transform(o)); }
/** * Transforms the specified object into an instance of this class. * * @param o The object to transform. * @return The transformed object. */ @SuppressWarnings({"unchecked","rawtypes"}) public T transformFrom(Object o) { Transform t = getFromTransform(o.getClass()); return (T)(t == null ? null : t.transform(o)); }
/** * Transforms the specified object into an instance of this class. * * @param o The object to transform. * @param c The class * @return The transformed object. */ @SuppressWarnings({"unchecked","rawtypes"}) public <O> O transformTo(Object o, Class<O> c) { Transform t = getToTransform(c); return (O)(t == null ? null : t.transform(o)); }
/** * Converts an object to a string. * * <p> * Normally, this is just going to call <code>toString()</code> on the object. * However, the {@link Locale} and {@link TimeZone} objects are treated special so that the returned value * works with the {@link #fromString(Class, String)} method. * * @param o The object to convert to a string. * @return The stringified object, or <jk>null</jk> if the object was <jk>null</jk>. */ @SuppressWarnings({ "unchecked" }) public static String toString(Object o) { if (o == null) return null; Transform<Object,String> t = (Transform<Object,String>)TransformCache.get(o.getClass(), String.class); return t == null ? o.toString() : t.transform(o); }
/** * Converts an object to a string. * * <p> * Normally, this is just going to call <code>toString()</code> on the object. * However, the {@link Locale} and {@link TimeZone} objects are treated special so that the returned value * works with the {@link #fromString(Class, String)} method. * * @param o The object to convert to a string. * @return The stringified object, or <jk>null</jk> if the object was <jk>null</jk>. */ @SuppressWarnings({ "unchecked" }) public static String toString(Object o) { if (o == null) return null; Transform<Object,String> t = (Transform<Object,String>)TransformCache.get(o.getClass(), String.class); return t == null ? o.toString() : t.transform(o); }
/** * Constructs a new instance of the specified class from the specified string. * * <p> * Class must be one of the following: * <ul> * <li>Have a public constructor that takes in a single <code>String</code> argument. * <li>Have a static <code>fromString(String)</code> (or related) method. * <br>See {@link #findPublicFromStringMethod(Class)} for the list of possible static method names. * <li>Be an <code>enum</code>. * </ul> * * @param c The class. * @param s The string to create the instance from. * @return A new object instance, or <jk>null</jk> if a method for converting the string to an object could not be found. */ public static <T> T fromString(Class<T> c, String s) { Transform<String,T> t = TransformCache.get(String.class, c); return t == null ? null : t.transform(s); }
/** * Converts an object to a string. * * <p> * Normally, this is just going to call <code>toString()</code> on the object. * However, the {@link Locale} and {@link TimeZone} objects are treated special so that the returned value * works with the {@link #fromString(Class, String)} method. * * @param o The object to convert to a string. * @return The stringified object, or <jk>null</jk> if the object was <jk>null</jk>. */ @SuppressWarnings({ "unchecked" }) public static String toString(Object o) { if (o == null) return null; Transform<Object,String> t = (Transform<Object,String>)TransformCache.get(o.getClass(), String.class); return t == null ? o.toString() : t.transform(o); }
/** * Constructs a new instance of the specified class from the specified string. * * <p> * Class must be one of the following: * <ul> * <li>Have a public constructor that takes in a single <code>String</code> argument. * <li>Have a static <code>fromString(String)</code> (or related) method. * <br>See {@link #findPublicFromStringMethod(Class)} for the list of possible static method names. * <li>Be an <code>enum</code>. * </ul> * * @param c The class. * @param s The string to create the instance from. * @return A new object instance, or <jk>null</jk> if a method for converting the string to an object could not be found. */ public static <T> T fromString(Class<T> c, String s) { Transform<String,T> t = TransformCache.get(String.class, c); return t == null ? null : t.transform(s); }
/** * Constructs a new instance of the specified class from the specified string. * * <p> * Class must be one of the following: * <ul> * <li>Have a public constructor that takes in a single <code>String</code> argument. * <li>Have a static <code>fromString(String)</code> (or related) method. * <br>See {@link #findPublicFromStringMethod(Class)} for the list of possible static method names. * <li>Be an <code>enum</code>. * </ul> * * @param c The class. * @param s The string to create the instance from. * @return A new object instance, or <jk>null</jk> if a method for converting the string to an object could not be found. */ public static <T> T fromString(Class<T> c, String s) { Transform<String,T> t = TransformCache.get(String.class, c); return t == null ? null : t.transform(s); }
@Test public void stringConstructor() { assertEquals("foo", get(String.class, A.class).transform("foo").f); } @Test
@Test public void fromString_forName() { assertEquals("foo", get(String.class, D7.class).transform("foo").f); }
@Test public void intConstructor() { assertEquals("1", get(int.class, A.class).transform(1).f); } @Test
@Test public void fromString_fromValue() { assertEquals("foo", get(String.class, D3.class).transform("foo").f); }
@Test public void integerConstructor() { assertEquals("2", get(Integer.class, A.class).transform(2).f); }