app/src/main/java/db/juhaku/juhakudb/core/android/EntityConverter.java
/*
     * Constructs value and return as given class.
     */
Constructs value and return as given class.
Constructs value and return as given class .
private <T> T constructType(Class<?> clazz, T value) {
        try {
            if (clazz.isAnnotationPresent(Entity.class)) {
                clazz = ReflectionUtils.getFieldType(ReflectionUtils.findIdField(clazz));
            }
            Constructor<?> constructor = null;
            for (Constructor c : clazz.getDeclaredConstructors()) {
                if (c.getParameterTypes().length == 1 && String.class.isAssignableFrom(c.getParameterTypes()[0])) {
                    constructor = c;
                    break;
                }
            }
            if (constructor != null) {
                return (T) constructor.newInstance(value.toString());
            } else {
                Log.w(getClass().getName(), "incompatible type: " + value.getClass() + " with value: " + value + " for class: "
                        + clazz + ", returning null");
                return null;
            }
        } catch (Exception e) {
            throw new ConversionException("Failed to construct type: " + value.getClass() + " with value: " + value
                    + " for class: " + clazz, e);
        }
    }
private < T > T constructType ( Class < ? > clazz , T value ) { try { if ( clazz . isAnnotationPresent ( Entity . class ) ) { clazz = ReflectionUtils . getFieldType ( ReflectionUtils . findIdField ( clazz ) ) ; } Constructor < ? > constructor = null ; for ( Constructor c : clazz . getDeclaredConstructors ( ) ) { if ( c . getParameterTypes ( ) . length == 1 && String . class . isAssignableFrom ( c . getParameterTypes ( ) [ 0 ] ) ) { constructor = c ; break ; } } if ( constructor != null ) { return ( T ) constructor . newInstance ( value . toString ( ) ) ; } else { Log . w ( getClass ( ) . getName ( ) , "incompatible type: " + value . getClass ( ) + " with value: " + value + " for class: " + clazz + ", returning null" ) ; return null ; } } catch ( Exception e ) { throw new ConversionException ( "Failed to construct type: " + value . getClass ( ) + " with value: " + value + " for class: " + clazz , e ) ; } }
Constructs value and return as given class.
Constructs value and return as given class .