br.com.tecsinapse.exporter.txt.FieldTxt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tecsinapse-data-io Show documentation
Show all versions of tecsinapse-data-io Show documentation
A simple way to work with CSV, XLSX? and TXT files
/*
* Tecsinapse Data Input and Output
*
* License: GNU Lesser General Public License (LGPL), version 3 or later
* See the LICENSE file in the root directory or .
*/
package br.com.tecsinapse.exporter.txt;
import br.com.tecsinapse.exporter.type.SeparatorType;
/**
* Representa cada coluna de uma linha no arquivo {@code .txt}
*
* Exemplo de criação de um FieldTxt:
*
*
* {@code
* FieldTxt.newBuilder()
* .withContent("12345")
* .withAlign(FieldTxtAlign.RIGHT)
* .withFixedSize(20)
* .withFiller("0")
* .withSeparator(SeparatorTxt.TAB)
* .build();
* }
*
* Valores padrões:
*
*
* - separator: Separator.NONE
* - fixedSize: 0
* - filler: ' '
* - align: FieldTxtAlign.LEFT
*
*/
public class FieldTxt {
private String content;
private FieldTxtAlign align;
private SeparatorType separator;
private int fixedSize;
private String filler;
private FieldTxt(Builder builder) {
this.content = builder.content;
this.align = builder.align;
this.separator = builder.separator;
this.fixedSize = builder.fixedSize;
this.filler = builder.filler;
}
public static Builder newBuilder() {
return new Builder();
}
public FieldTxtAlign getAlign() {
return align;
}
public String getContent() {
return content != null ? content : "";
}
public String getSeparator() {
return separator.getSeparator();
}
public int getFixedSize() {
return fixedSize;
}
public String getFiller() {
return filler;
}
public String getValue() {
return align.getValueAligned(this);
}
public static final class Builder {
private String content;
private FieldTxtAlign align = FieldTxtAlign.LEFT;
private SeparatorType separator = SeparatorType.NONE;
private int fixedSize = 0;
private String filler = " ";
private Builder() {
}
public FieldTxt build() {
return new FieldTxt(this);
}
public Builder withContent(String content) {
this.content = content;
return this;
}
public Builder withAlign(FieldTxtAlign align) {
this.align = align;
return this;
}
public Builder withSeparator(SeparatorType separator) {
this.separator = separator;
return this;
}
public Builder withFixedSize(int fixedSize) {
this.fixedSize = fixedSize;
return this;
}
public Builder withFiller(String filler) {
this.filler = filler;
return this;
}
}
}