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

org.simpleflatmapper.map.impl.StaticMapperEnumerable 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.impl;

import org.simpleflatmapper.map.SourceMapper;
import org.simpleflatmapper.map.MappingContext;
import org.simpleflatmapper.util.Enumerable;

public class StaticMapperEnumerable implements Enumerable {

    private final SourceMapper mapper;
    private final MappingContext mappingContext;


    private final Enumerable sourceEnumerable;
    private T currentValue;

    public StaticMapperEnumerable(SourceMapper mapper,
                                  MappingContext mappingContext,
                                  Enumerable sourceEnumerable) {
        this.mapper = mapper;
        this.mappingContext = mappingContext;
        this.sourceEnumerable = sourceEnumerable;
    }

    @Override
    public boolean next() {
        if (sourceEnumerable.next()) {
            currentValue = mapper.map(sourceEnumerable.currentValue(), mappingContext);
            return true;
        } else return false;
    }

    @Override
    public T currentValue() {
        return currentValue;
    }

    @Override
    public String toString() {
        return "StaticMapperEnumerable{" +
                "jdbcMapper=" + mapper +
                '}';
    }
}