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

com.github.skjolber.stcsv.column.bi.LongCsvFieldMapperBuilder 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.ObjLongConsumer;

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 LongCsvFieldMapperBuilder> extends AbstractCsvFieldMapperBuilder {

	protected ObjLongConsumer consumer;
	protected ObjLongConsumer setter;

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

	public LongCsvFieldMapperBuilder consumer(ObjLongConsumer consumer) {
		this.consumer = consumer;
		
		return this;
	}

	public LongCsvFieldMapperBuilder setter(ObjLongConsumer setter) {
		this.setter = setter;
		
		return this;
	}
	
	public LongCsvFieldMapperBuilder 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 LongCsvFieldMapperBuilder quoted() {
		super.quoted();
		
		return this;
	}

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

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

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

	@Override
	protected Class getColumnClass() {
		return long.class;
	}

	@Override
	protected void invokeSetter(T value) {
		setter.accept(value, 0L);
	}
	
	@Override
	protected boolean hasSetter() {
		return setter != null;
	}
	
	protected ValueProjection getProjection(int index, SetterProjectionHelper proxy) throws CsvBuilderException {
		if(consumer != null) {
			return new BiConsumerProjection(new LongCsvColumnValueConsumer<>(consumer), index);
		}
		return super.getProjection(index, proxy);
	}

}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy