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

org.simpleflatmapper.map.mapper.TransformEnumerableMapper 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.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 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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy