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

org.simpleflatmapper.map.context.impl.ValuedMappingContextFactory Maven / Gradle / Ivy

Go to download

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

The newest version!
package org.simpleflatmapper.map.context.impl;

import org.simpleflatmapper.map.MappingContext;
import org.simpleflatmapper.map.context.MappingContextFactory;
import org.simpleflatmapper.util.Supplier;

import java.util.List;

public class ValuedMappingContextFactory implements MappingContextFactory {
    private final Supplier[] suppliers;

    public ValuedMappingContextFactory(List> suppliers) {
        this.suppliers = suppliers.toArray(new Supplier[0]);

    }

    @Override
    public MappingContext newContext() {
        return new ValuedMappingContext(getObjects());
    }

    protected Object[] getObjects() {
        Object[] values = new Object[suppliers.length];

        for(int i = 0; i < suppliers.length; i ++) {
            Supplier s = suppliers[i];
            if (s != null) {
                values[i] = s.get();
            }
        }
        return values;
    }
}