boon/src/main/java/org/boon/core/reflection/MapperSimple.java
private  void processCollectionFromMapUsingFields(final Object newInstance,
                                                      final FieldAccess field,
                                                      final Collection<?> collection ) {
        final Class<?> fieldComponentClass = field.getComponentClass();

        final Class<?> valueComponentClass = Reflection.getComponentType(collection);


        /** See if we have a collection of maps because if we do, then we have some
         * recursive processing to do.
         */
        if ( Typ.isMap( valueComponentClass ) ) {
            handleCollectionOfMaps( newInstance, field,
                    ( Collection<Map<String, Object>> ) collection );
            return;

        }

        /** See if this is a value object of some sort. */
        if ( Typ.isValue( valueComponentClass ) ) {
            handleCollectionOfValues( newInstance, field,
                    ( Collection<Value> ) collection );
            return;
        }


        /**
         * See if the collection implements the same type as the field.
         * I saw a few places that could have used this helper method earlier in the file but were not.
         */
        if (Typ.implementsInterface( collection.getClass(), field.type() )) {

            if (fieldComponentClass!=null && fieldComponentClass.isAssignableFrom(valueComponentClass)) {
                field.setValue(newInstance, collection);

                return;
            }

        }

        /** See if this is some sort of collection.
         * TODO we need a coerce that needs a respectIgnore
         *
         * REFACTOR:
         * Note we are assuming it is a collection of instances.
         * We don't handle enums here.
         *
         * We do in other places.
         *
         * We handle all sorts of generics but not here.
         *
         * REFACTOR
         *
         **/
        if (!field.typeEnum().isCollection()) {
            if (collection instanceof List) {
                try {
                    Object value = fromList( (List) collection, field.getComponentClass());
                    field.setValue(newInstance, value);
                } catch  (Exception ex) {
                    //There is an edge case that needs this. We need a coerce that takes respectIngore, etc.
                    field.setValue(newInstance, collection);
                }
            } else {
                field.setValue(newInstance, collection);
            }
            return;
        }


        /**
         * Create a new collection. if the types already match then just copy them over.
         * Note that this is currently untyped in the null case.
         * We are relying on the fact that the field.setValue calls the Conversion.coerce.
         */
        Collection<Object> newCollection = Conversions.createCollection( field.type(), collection.size() );

        if ( fieldComponentClass == null || fieldComponentClass.isAssignableFrom(valueComponentClass)) {

            newCollection.addAll(collection);
            field.setValue( newInstance, newCollection );
            return;
        }



        /* Here we try to do the coercion for each individual collection item. */
        for (Object itemValue : collection) {
            newCollection.add(Conversions.coerce(fieldComponentClass, itemValue));
            field.setValue(newInstance, newCollection);
        }

    }
private  void processCollectionFromMapUsingFields(final Object newInstance,
                                                      final FieldAccess field,
                                                      final Collection<?> collection ) {
        final Class<?> fieldComponentClass = field.getComponentClass();

        final Class<?> valueComponentClass = Reflection.getComponentType(collection);


        /** See if we have a collection of maps because if we do, then we have some
         * recursive processing to do.
         */
        if ( Typ.isMap( valueComponentClass ) ) {
            handleCollectionOfMaps( newInstance, field,
                    ( Collection<Map<String, Object>> ) collection );
            return;

        }

        /** See if this is a value object of some sort. */
        if ( Typ.isValue( valueComponentClass ) ) {
            handleCollectionOfValues( newInstance, field,
                    ( Collection<Value> ) collection );
            return;
        }


        /**
         * See if the collection implements the same type as the field.
         * I saw a few places that could have used this helper method earlier in the file but were not.
         */
        if (Typ.implementsInterface( collection.getClass(), field.type() )) {

            if (fieldComponentClass!=null && fieldComponentClass.isAssignableFrom(valueComponentClass)) {
                field.setValue(newInstance, collection);

                return;
            }

        }

        /** See if this is some sort of collection.
         * TODO we need a coerce that needs a respectIgnore
         *
         * REFACTOR:
         * Note we are assuming it is a collection of instances.
         * We don't handle enums here.
         *
         * We do in other places.
         *
         * We handle all sorts of generics but not here.
         *
         * REFACTOR
         *
         **/
        if (!field.typeEnum().isCollection()) {
            if (collection instanceof List) {
                try {
                    Object value = fromList( (List) collection, field.getComponentClass());
                    field.setValue(newInstance, value);
                } catch  (Exception ex) {
                    //There is an edge case that needs this. We need a coerce that takes respectIngore, etc.
                    field.setValue(newInstance, collection);
                }
            } else {
                field.setValue(newInstance, collection);
            }
            return;
        }


        /**
         * Create a new collection. if the types already match then just copy them over.
         * Note that this is currently untyped in the null case.
         * We are relying on the fact that the field.setValue calls the Conversion.coerce.
         */
        Collection<Object> newCollection = Conversions.createCollection( field.type(), collection.size() );

        if ( fieldComponentClass == null || fieldComponentClass.isAssignableFrom(valueComponentClass)) {

            newCollection.addAll(collection);
            field.setValue( newInstance, newCollection );
            return;
        }



        /* Here we try to do the coercion for each individual collection item. */
        for (Object itemValue : collection) {
            newCollection.add(Conversions.coerce(fieldComponentClass, itemValue));
            field.setValue(newInstance, newCollection);
        }

    }
private void processCollectionFromMapUsingFields ( final Object newInstance , final FieldAccess field , final Collection < ? > collection ) { final Class < ? > fieldComponentClass = field . getComponentClass ( ) ; final Class < ? > valueComponentClass = Reflection . getComponentType ( collection ) ; /** See if we have a collection of maps because if we do, then we have some
         * recursive processing to do.
         */ if ( Typ . isMap ( valueComponentClass ) ) { handleCollectionOfMaps ( newInstance , field , ( Collection < Map < String , Object > > ) collection ) ; return ; } /** See if this is a value object of some sort. */ if ( Typ . isValue ( valueComponentClass ) ) { handleCollectionOfValues ( newInstance , field , ( Collection < Value > ) collection ) ; return ; } /**
         * See if the collection implements the same type as the field.
         * I saw a few places that could have used this helper method earlier in the file but were not.
         */ if ( Typ . implementsInterface ( collection . getClass ( ) , field . type ( ) ) ) { if ( fieldComponentClass != null && fieldComponentClass . isAssignableFrom ( valueComponentClass ) ) { field . setValue ( newInstance , collection ) ; return ; } } /** See if this is some sort of collection.
         * TODO we need a coerce that needs a respectIgnore
         *
         * REFACTOR:
         * Note we are assuming it is a collection of instances.
         * We don't handle enums here.
         *
         * We do in other places.
         *
         * We handle all sorts of generics but not here.
         *
         * REFACTOR
         *
         **/ if ( ! field . typeEnum ( ) . isCollection ( ) ) { if ( collection instanceof List ) { try { Object value = fromList ( ( List ) collection , field . getComponentClass ( ) ) ; field . setValue ( newInstance , value ) ; } catch ( Exception ex ) { //There is an edge case that needs this. We need a coerce that takes respectIngore, etc. field . setValue ( newInstance , collection ) ; } } else { field . setValue ( newInstance , collection ) ; } return ; } /**
         * Create a new collection. if the types already match then just copy them over.
         * Note that this is currently untyped in the null case.
         * We are relying on the fact that the field.setValue calls the Conversion.coerce.
         */ Collection < Object > newCollection = Conversions . createCollection ( field . type ( ) , collection . size ( ) ) ; if ( fieldComponentClass == null || fieldComponentClass . isAssignableFrom ( valueComponentClass ) ) { newCollection . addAll ( collection ) ; field . setValue ( newInstance , newCollection ) ; return ; } /* Here we try to do the coercion for each individual collection item. */ for ( Object itemValue : collection ) { newCollection . add ( Conversions . coerce ( fieldComponentClass , itemValue ) ) ; field . setValue ( newInstance , newCollection ) ; } }
Helper method to extract collection of values into some field collection.
REFACTOR:
This could be refactored to use the org.boon.core.TypeType system which should be faster.
REFACTOR
@param collection the collection we are coercing into a field value
Helper method to extract collection of values into some field collection . REFACTOR : This could be refactored to use the org . boon . core . TypeType system which should be faster . REFACTOR