org.bklab.export.data.ColumnDataBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fluent-vaadin-flow Show documentation
Show all versions of fluent-vaadin-flow Show documentation
Broderick Labs for fluent vaadin flow. Inherits common Vaadin components.
package org.bklab.export.data;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import java.util.*;
import java.util.function.BiConsumer;
public class ColumnDataBuilder {
private final Map> map = new LinkedHashMap<>();
private final List disableExport = new ArrayList<>();
private final List> headers = new ArrayList<>();
private final Map alignMap = new LinkedHashMap<>();
private boolean hasDefaultHeader = true;
public ColumnDataBuilder() {
}
public ColumnDataBuilder(Map> map) {
this.map.putAll(map);
}
public ColumnDataBuilder hasDefaultHeader(boolean defaultHeader) {
this.hasDefaultHeader = defaultHeader;
return this;
}
public ColumnDataBuilder header(String... names) {
return this.header(new ArrayList<>(Arrays.asList(names)));
}
public ColumnDataBuilder header(Collection names) {
this.headers.add(names);
return this;
}
public ColumnDataBuilder align(String name, HorizontalAlignment textAlign) {
this.alignMap.put(name, textAlign);
return this;
}
public ColumnDataBuilder align(Map textAlignMap) {
this.alignMap.putAll(textAlignMap);
return this;
}
public ColumnDataBuilder add(String name, IColumnDataSupplier supplier) {
this.map.put(name, supplier);
return this;
}
public ColumnDataBuilder add(String name, HorizontalAlignment textAlign, IColumnDataSupplier supplier) {
this.map.put(name, supplier);
this.alignMap.put(name, textAlign);
return this;
}
public ColumnDataBuilder disableExport(String... names) {
Collections.addAll(disableExport, names);
return this;
}
public void forEach(BiConsumer> action) {
Objects.requireNonNull(action);
for (Map.Entry> entry : map.entrySet()) {
if (disableExport.contains(entry.getKey())) continue;
action.accept(entry.getKey(), entry.getValue());
}
}
public Map> getMap() {
return map;
}
public List getDisableExport() {
return disableExport;
}
public List> getHeaders() {
return headers;
}
public boolean hasDefaultHeader() {
return hasDefaultHeader;
}
public int columnSize() {
return map.size();
}
public HorizontalAlignment getAlign(String name) {
return Optional.ofNullable(alignMap.get(name)).orElse(HorizontalAlignment.CENTER);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy