boon/src/main/java/org/boon/core/reflection/MapperSimple.java
@SuppressWarnings("unchecked")
    private  void handleCollectionOfValues(
            Object newInstance,
            FieldAccess field, Collection<Value> acollectionOfValues ) {

        Collection collectionOfValues = acollectionOfValues;
        if (null == collectionOfValues) {
            field.setObject(newInstance, null);
            return;
        }

        if(field.typeEnum() == INSTANCE) {

            field.setObject(newInstance, fromList((List) acollectionOfValues, field.type()));
            return;

        }

        if ( collectionOfValues instanceof ValueList) {
            collectionOfValues = ( ( ValueList ) collectionOfValues ).list();
        }


        Class<?> componentClass = field.getComponentClass();



        /** If the field is a collection than try to convert the items in the collection to
         * the field type.
         */
        switch (field.typeEnum() ) {


            case LIST:
            case SET:
            case COLLECTION:


                Collection<Object> newCollection = Conversions.createCollection( field.type(), collectionOfValues.size() );


                for ( Value value : ( List<Value> ) collectionOfValues ) {

                    if ( value.isContainer() ) {
                        Object oValue = value.toValue();
                        if ( oValue instanceof Map ) {
                            newCollection.add( fromValueMap(  ( Map ) oValue, componentClass ) );
                        }
                    } else {
                        newCollection.add( Conversions.coerce( componentClass, value.toValue() ) );
                    }


                }
                field.setObject( newInstance, newCollection );
                break;


            case ARRAY:
            case ARRAY_INT:
            case ARRAY_BYTE:
            case ARRAY_SHORT:
            case ARRAY_FLOAT:
            case ARRAY_DOUBLE:
            case ARRAY_LONG:
            case ARRAY_STRING:
            case ARRAY_OBJECT:

                TypeType componentType =  field.componentType();
                int index = 0;

                switch (componentType) {
                    case INT:
                        int [] iarray = new int[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            iarray[index] = value.intValue();
                            index++;

                        }
                        field.setObject( newInstance, iarray);
                        return;
                    case SHORT:
                        short [] sarray = new short[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            sarray[index] = value.shortValue();
                            index++;

                        }
                        field.setObject( newInstance, sarray);
                        return;
                    case DOUBLE:
                        double [] darray = new double[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            darray[index] = value.doubleValue();
                            index++;

                        }
                        field.setObject( newInstance, darray);
                        return;
                    case FLOAT:
                        float [] farray = new float[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            farray[index] = value.floatValue();
                            index++;

                        }
                        field.setObject( newInstance, farray);
                        return;

                    case LONG:
                        long [] larray = new long[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            larray[index] = value.longValue();
                            index++;

                        }
                        field.setObject( newInstance, larray);
                        return;


                    case BYTE:
                        byte [] barray = new byte[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            barray[index] = value.byteValue();
                            index++;

                        }
                        field.setObject( newInstance, barray);
                        return;


                    case CHAR:
                        char [] chars = new char[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            chars[index] = value.charValue();
                            index++;
                        }
                        field.setObject( newInstance, chars);
                        return;

                    case STRING:
                        CharBuf buffer = CharBuf.create(100);
                        String [] strings = new String[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            strings[index] = value.stringValue(buffer);
                            index++;
                        }
                        field.setObject( newInstance, strings);
                        return;


                    default:
                        Object array = Array.newInstance(componentClass, collectionOfValues.size());
                        Object o;

                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            if (value instanceof ValueContainer) {
                                o = value.toValue();
                                if (o instanceof List) {
                                    o = fromList( (List)o, componentClass);
                                    if (componentClass.isInstance( o )) {
                                        Array.set(array, index, o);
                                    } else {
                                        break;
                                    }
                                } else if (o instanceof  Map) {
                                    o = fromMap((Map) o, componentClass);
                                    if (componentClass.isInstance( o )) {
                                        Array.set(array, index, o);
                                    } else {
                                        break;
                                    }
                                }
                            } else {
                                o = value.toValue();
                                if (componentClass.isInstance( o )) {
                                    Array.set(array, index, o);
                                } else {
                                    Array.set(array, index, Conversions.coerce( componentClass, o ));
                                }
                            }
                            index++;
                        }
                        field.setValue( newInstance, array);
                }
                break;
        }

    }
@SuppressWarnings("unchecked")
    private  void handleCollectionOfValues(
            Object newInstance,
            FieldAccess field, Collection<Value> acollectionOfValues ) {

        Collection collectionOfValues = acollectionOfValues;
        if (null == collectionOfValues) {
            field.setObject(newInstance, null);
            return;
        }

        if(field.typeEnum() == INSTANCE) {

            field.setObject(newInstance, fromList((List) acollectionOfValues, field.type()));
            return;

        }

        if ( collectionOfValues instanceof ValueList) {
            collectionOfValues = ( ( ValueList ) collectionOfValues ).list();
        }


        Class<?> componentClass = field.getComponentClass();



        /** If the field is a collection than try to convert the items in the collection to
         * the field type.
         */
        switch (field.typeEnum() ) {


            case LIST:
            case SET:
            case COLLECTION:


                Collection<Object> newCollection = Conversions.createCollection( field.type(), collectionOfValues.size() );


                for ( Value value : ( List<Value> ) collectionOfValues ) {

                    if ( value.isContainer() ) {
                        Object oValue = value.toValue();
                        if ( oValue instanceof Map ) {
                            newCollection.add( fromValueMap(  ( Map ) oValue, componentClass ) );
                        }
                    } else {
                        newCollection.add( Conversions.coerce( componentClass, value.toValue() ) );
                    }


                }
                field.setObject( newInstance, newCollection );
                break;


            case ARRAY:
            case ARRAY_INT:
            case ARRAY_BYTE:
            case ARRAY_SHORT:
            case ARRAY_FLOAT:
            case ARRAY_DOUBLE:
            case ARRAY_LONG:
            case ARRAY_STRING:
            case ARRAY_OBJECT:

                TypeType componentType =  field.componentType();
                int index = 0;

                switch (componentType) {
                    case INT:
                        int [] iarray = new int[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            iarray[index] = value.intValue();
                            index++;

                        }
                        field.setObject( newInstance, iarray);
                        return;
                    case SHORT:
                        short [] sarray = new short[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            sarray[index] = value.shortValue();
                            index++;

                        }
                        field.setObject( newInstance, sarray);
                        return;
                    case DOUBLE:
                        double [] darray = new double[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            darray[index] = value.doubleValue();
                            index++;

                        }
                        field.setObject( newInstance, darray);
                        return;
                    case FLOAT:
                        float [] farray = new float[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            farray[index] = value.floatValue();
                            index++;

                        }
                        field.setObject( newInstance, farray);
                        return;

                    case LONG:
                        long [] larray = new long[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            larray[index] = value.longValue();
                            index++;

                        }
                        field.setObject( newInstance, larray);
                        return;


                    case BYTE:
                        byte [] barray = new byte[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            barray[index] = value.byteValue();
                            index++;

                        }
                        field.setObject( newInstance, barray);
                        return;


                    case CHAR:
                        char [] chars = new char[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            chars[index] = value.charValue();
                            index++;
                        }
                        field.setObject( newInstance, chars);
                        return;

                    case STRING:
                        CharBuf buffer = CharBuf.create(100);
                        String [] strings = new String[collectionOfValues.size()];
                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            strings[index] = value.stringValue(buffer);
                            index++;
                        }
                        field.setObject( newInstance, strings);
                        return;


                    default:
                        Object array = Array.newInstance(componentClass, collectionOfValues.size());
                        Object o;

                        for ( Value value : ( List<Value> ) collectionOfValues ) {
                            if (value instanceof ValueContainer) {
                                o = value.toValue();
                                if (o instanceof List) {
                                    o = fromList( (List)o, componentClass);
                                    if (componentClass.isInstance( o )) {
                                        Array.set(array, index, o);
                                    } else {
                                        break;
                                    }
                                } else if (o instanceof  Map) {
                                    o = fromMap((Map) o, componentClass);
                                    if (componentClass.isInstance( o )) {
                                        Array.set(array, index, o);
                                    } else {
                                        break;
                                    }
                                }
                            } else {
                                o = value.toValue();
                                if (componentClass.isInstance( o )) {
                                    Array.set(array, index, o);
                                } else {
                                    Array.set(array, index, Conversions.coerce( componentClass, o ));
                                }
                            }
                            index++;
                        }
                        field.setValue( newInstance, array);
                }
                break;
        }

    }
@ SuppressWarnings ( "unchecked" ) private void handleCollectionOfValues ( Object newInstance , FieldAccess field , Collection < Value > acollectionOfValues ) { Collection collectionOfValues = acollectionOfValues ; if ( null == collectionOfValues ) { field . setObject ( newInstance , null ) ; return ; } if ( field . typeEnum ( ) == INSTANCE ) { field . setObject ( newInstance , fromList ( ( List ) acollectionOfValues , field . type ( ) ) ) ; return ; } if ( collectionOfValues instanceof ValueList ) { collectionOfValues = ( ( ValueList ) collectionOfValues ) . list ( ) ; } Class < ? > componentClass = field . getComponentClass ( ) ; /** If the field is a collection than try to convert the items in the collection to
         * the field type.
         */ switch ( field . typeEnum ( ) ) { case LIST : case SET : case COLLECTION : Collection < Object > newCollection = Conversions . createCollection ( field . type ( ) , collectionOfValues . size ( ) ) ; for ( Value value : ( List < Value > ) collectionOfValues ) { if ( value . isContainer ( ) ) { Object oValue = value . toValue ( ) ; if ( oValue instanceof Map ) { newCollection . add ( fromValueMap ( ( Map ) oValue , componentClass ) ) ; } } else { newCollection . add ( Conversions . coerce ( componentClass , value . toValue ( ) ) ) ; } } field . setObject ( newInstance , newCollection ) ; break ; case ARRAY : case ARRAY_INT : case ARRAY_BYTE : case ARRAY_SHORT : case ARRAY_FLOAT : case ARRAY_DOUBLE : case ARRAY_LONG : case ARRAY_STRING : case ARRAY_OBJECT : TypeType componentType = field . componentType ( ) ; int index = 0 ; switch ( componentType ) { case INT : int [ ] iarray = new int [ collectionOfValues . size ( ) ] ; for ( Value value : ( List < Value > ) collectionOfValues ) { iarray [ index ] = value . intValue ( ) ; index ++ ; } field . setObject ( newInstance , iarray ) ; return ; case SHORT : short [ ] sarray = new short [ collectionOfValues . size ( ) ] ; for ( Value value : ( List < Value > ) collectionOfValues ) { sarray [ index ] = value . shortValue ( ) ; index ++ ; } field . setObject ( newInstance , sarray ) ; return ; case DOUBLE : double [ ] darray = new double [ collectionOfValues . size ( ) ] ; for ( Value value : ( List < Value > ) collectionOfValues ) { darray [ index ] = value . doubleValue ( ) ; index ++ ; } field . setObject ( newInstance , darray ) ; return ; case FLOAT : float [ ] farray = new float [ collectionOfValues . size ( ) ] ; for ( Value value : ( List < Value > ) collectionOfValues ) { farray [ index ] = value . floatValue ( ) ; index ++ ; } field . setObject ( newInstance , farray ) ; return ; case LONG : long [ ] larray = new long [ collectionOfValues . size ( ) ] ; for ( Value value : ( List < Value > ) collectionOfValues ) { larray [ index ] = value . longValue ( ) ; index ++ ; } field . setObject ( newInstance , larray ) ; return ; case BYTE : byte [ ] barray = new byte [ collectionOfValues . size ( ) ] ; for ( Value value : ( List < Value > ) collectionOfValues ) { barray [ index ] = value . byteValue ( ) ; index ++ ; } field . setObject ( newInstance , barray ) ; return ; case CHAR : char [ ] chars = new char [ collectionOfValues . size ( ) ] ; for ( Value value : ( List < Value > ) collectionOfValues ) { chars [ index ] = value . charValue ( ) ; index ++ ; } field . setObject ( newInstance , chars ) ; return ; case STRING : CharBuf buffer = CharBuf . create ( 100 ) ; String [ ] strings = new String [ collectionOfValues . size ( ) ] ; for ( Value value : ( List < Value > ) collectionOfValues ) { strings [ index ] = value . stringValue ( buffer ) ; index ++ ; } field . setObject ( newInstance , strings ) ; return ; default : Object array = Array . newInstance ( componentClass , collectionOfValues . size ( ) ) ; Object o ; for ( Value value : ( List < Value > ) collectionOfValues ) { if ( value instanceof ValueContainer ) { o = value . toValue ( ) ; if ( o instanceof List ) { o = fromList ( ( List ) o , componentClass ) ; if ( componentClass . isInstance ( o ) ) { Array . set ( array , index , o ) ; } else { break ; } } else if ( o instanceof Map ) { o = fromMap ( ( Map ) o , componentClass ) ; if ( componentClass . isInstance ( o ) ) { Array . set ( array , index , o ) ; } else { break ; } } } else { o = value . toValue ( ) ; if ( componentClass . isInstance ( o ) ) { Array . set ( array , index , o ) ; } else { Array . set ( array , index , Conversions . coerce ( componentClass , o ) ) ; } } index ++ ; } field . setValue ( newInstance , array ) ; } break ; } }
Processes an collection of maps.
This can inject into an array and appears to be using some of the TypeType lib.
@param newInstance  new instance we are injecting field into
@param field    field we are injecting a value into
Processes an collection of maps . This can inject into an array and appears to be using some of the TypeType lib .