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

com.github.skjolber.stcsv.column.bi.StringCsvFieldMapperBuilder Maven / Gradle / Ivy

There is a newer version: 1.0.25
Show newest version
package com.github.skjolber.stcsv.column.bi;

import java.util.function.BiConsumer;

import com.github.skjolber.stcsv.builder.AbstractCsvFieldMapperBuilder;
import com.github.skjolber.stcsv.builder.AbstractCsvMappingBuilder;
import com.github.skjolber.stcsv.builder.CsvBuilderException;
import com.github.skjolber.stcsv.builder.SetterProjectionHelper;
import com.github.skjolber.stcsv.projection.BiConsumerProjection;
import com.github.skjolber.stcsv.projection.ValueProjection;

public class StringCsvFieldMapperBuilder> extends AbstractCsvFieldMapperBuilder {

	protected BiConsumer consumer;
	protected BiConsumer setter;

	public StringCsvFieldMapperBuilder(B parent, String name) {
		super(parent, name);
	}

	public StringCsvFieldMapperBuilder consumer(BiConsumer consumer) {
		this.consumer = consumer;
		
		return this;
	}

	public StringCsvFieldMapperBuilder setter(BiConsumer setter) {
		this.setter = setter;
		
		return this;
	}
	
	public StringCsvFieldMapperBuilder fixedSize(int fixedSize) {
		super.fixedSize(fixedSize);
		
		return this;
	}

	/**
	 * Indicate that this field is quoted. If there is no linebreaks, 
	 * rather use the method {@linkplain #quotedWithoutLinebreaks()} to improve performance.
	 * 
	 * @return this instance.
	 */
	
	public StringCsvFieldMapperBuilder quoted() {
		super.quoted();
		
		return this;
	}

	/**
	 * Indicate that this field is quoted, but has no linebreaks.
	 * 
	 * @return this instance.
	 */
	public StringCsvFieldMapperBuilder quotedWithoutLinebreaks() {
		super.quotedWithoutLinebreaks();
		
		return this;
	}

	public StringCsvFieldMapperBuilder trimTrailingWhitespaces() {
		super.trimTrailingWhitespaces();
		
		return this;
	}

	public StringCsvFieldMapperBuilder trimLeadingWhitespaces() {
		super.trimLeadingWhitespaces();
		
		return this;
	}

	protected ValueProjection getProjection(int index, SetterProjectionHelper proxy) throws CsvBuilderException {
		if(consumer != null) {
			return new BiConsumerProjection(new StringCsvColumnValueConsumer<>(consumer), index);
		}
		return super.getProjection(index, proxy);
	}
	
	@Override
	protected Class getColumnClass() {
		return String.class;
	}

	@Override
	protected void invokeSetter(T value) {
		setter.accept(value, null);
	}

	@Override
	protected boolean hasSetter() {
		return setter != null;
	}
	
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy