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

org.simpleflatmapper.map.mapper.TransformSetRowMapper 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.MappingContext;
import org.simpleflatmapper.map.MappingException;
import org.simpleflatmapper.map.SetRowMapper;
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 TransformSetRowMapper implements SetRowMapper {

	private final SetRowMapper delegate;
	private final Function transformer;

	public TransformSetRowMapper(SetRowMapper 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);
	}

	@Override
	public Enumerable enumerate(SET source) throws E, MappingException {
		return new TransformEnumerable(delegate.enumerate(source), transformer);
	}

	//IFJAVA8_START
	@Override
	public Stream stream(SET source) throws E, MappingException {
		return delegate.stream(source).map(transformer::apply);
	}
	//IFJAVA8_END


	@Override
	public O map(ROW source) throws MappingException {
		return transformer.apply(delegate.map(source));
	}

	@Override
	public O map(ROW source, MappingContext context) throws MappingException {
		return transformer.apply(delegate.map(source, context));
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy