All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.simpleflatmapper.map.mapper.MapperImpl Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 9.0.2
Show newest version
package org.simpleflatmapper.map.mapper;

import org.simpleflatmapper.map.FieldMapper;
import org.simpleflatmapper.map.MappingContext;
import org.simpleflatmapper.reflect.BiInstantiator;

import java.util.Arrays;

public class MapperImpl extends AbstractMapper {
	
	private final FieldMapper[] fieldMappers;

    private final FieldMapper[] constructorMappers;

    public MapperImpl(final FieldMapper[] fieldMappers,
                      final FieldMapper[] constructorMappers,
                      final BiInstantiator, T> instantiator) {
		super(instantiator);
		this.fieldMappers = fieldMappers;
        this.constructorMappers = constructorMappers;
	}



    protected final void mapFields(final S source, final T target, final MappingContext mappingContext) throws Exception {
        for (FieldMapper fieldMapper : fieldMappers) {
            fieldMapper.mapTo(source, target, mappingContext);
        }
	}

    @Override
    protected final void mapToFields(S source, T target, final MappingContext mappingContext) throws Exception {
        for (FieldMapper constructorMapper : constructorMappers) {
            constructorMapper.mapTo(source, target, mappingContext);
        }

        mapFields(source, target, mappingContext);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();

        sb.append(getClass().getSimpleName())
                .append("{");

        super.appendToStringBuilder(sb);
        sb.append(", fieldMappers=").append(Arrays.toString(fieldMappers));
        sb.append("}");

        return sb.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy