org.simpleflatmapper.map.mapper.TransformEnumerableMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-map Show documentation
Show all versions of sfm-map Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.simpleflatmapper.map.mapper;
import org.simpleflatmapper.map.EnumerableMapper;
import org.simpleflatmapper.map.MappingException;
import org.simpleflatmapper.map.TransformEnumerable;
import org.simpleflatmapper.util.CheckedConsumer;
import org.simpleflatmapper.util.Enumerable;
import org.simpleflatmapper.util.Function;
import org.simpleflatmapper.util.TransformCheckedConsumer;
import org.simpleflatmapper.util.TransformIterator;
import java.util.Iterator;
//IFJAVA8_START
import java.util.stream.Stream;
//IFJAVA8_END
public final class TransformEnumerableMapper implements EnumerableMapper {
private final EnumerableMapper delegate;
private final Function super I, ? extends O> transformer;
public TransformEnumerableMapper(EnumerableMapper delegate, Function transformer) {
this.delegate = delegate;
this.transformer = transformer;
}
@Override
public > H forEach(SET source, final H handler) throws E, MappingException {
delegate.forEach(source, new TransformCheckedConsumer(handler, transformer));
return handler;
}
@Override
public Iterator iterator(SET source) throws E, MappingException {
return new TransformIterator(delegate.iterator(source), transformer);
}
//IFJAVA8_START
@Override
public Stream stream(SET source) throws E, MappingException {
return delegate.stream(source).map(transformer::apply);
}
//IFJAVA8_END
@Override
public Enumerable enumerate(SET source) throws E, MappingException {
return new TransformEnumerable(delegate.enumerate(source), transformer);
}
}