com.github.skjolber.stcsv.column.bi.StringCsvFieldMapperBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of databinder Show documentation
Show all versions of databinder Show documentation
High-performance CSV databinding library
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;
}
}