CellDef 사용 메소드 CellDef로 이동

master
mjkhan21 11 months ago
parent b1a60f4651
commit 657f7d0cf1

@ -5,14 +5,11 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
@ -474,19 +471,6 @@ public class XLSWriter extends XLS {
return cellStyle(new Styler().dataFormat("HH:mm:ss").merge(Styler.CENTER));
}
public List<Object> header(Iterable<CellDef> defs, Supplier<Styler> factory) {
ArrayList<Object> result = new ArrayList<>();
for (CellDef def: defs) {
result.add(def.label);
Styler styler = factory.get();
styler.width(def.width);
result.add(styler);
}
return result;
}
/** . {@link #set(CellStyle) CellStyle } .
* @author mjkhan
*/
@ -810,31 +794,122 @@ public class XLSWriter extends XLS {
}
}
/**
/**
* @author mjkhan
*/
public static class CellDef {
public static final Map<String, CellDef> toMap(CellDef... defs) {
return Stream.of(defs).collect(Collectors.toMap(
def -> def.label,
def -> def,
(k1, k2) -> k1,
LinkedHashMap::new
));
/**valueMap CellDef .
* @param defs CellDef
* @param valueMap
*/
public static void setValues(List<CellDef> defs, Map<String, Object> valueMap) {
defs.forEach(def -> {
Object val = valueMap.get(def.label);
if (val == null)
val = def.field;
if (isEmpty(val))
throw new RuntimeException("Value or style not found for " + def.label);
def.value = val;
});
}
/**CellDef .
* @param defs CellDef
* @param factory function
* @return
*/
public static List<Object> header(List<CellDef> defs, Supplier<Styler> factory) {
ArrayList<Object> result = new ArrayList<>();
for (CellDef def: defs) {
result.add(def.label);
Styler styler = factory.get();
styler.width(def.width);
result.add(styler);
}
return result;
}
private String label;
/**CellDef .
* @param defs CellDef
* @return
*/
public static Object[] values(List<CellDef> defs) {
return defs.stream().map(CellDef::getValue).toList().toArray();
}
private String
label,
field;
private int width;
private Object value;
public CellDef(String label, int width, Object value) {
/** .
* @return
*/
public String getLabel() {
return label;
}
/** .
* @param label
* @return CellDef
*/
public CellDef setLabel(String label) {
this.label = label;
return this;
}
/** .
* @return
*/
public String getField() {
return field;
}
/** .
* @param field
* @return CellDef
*/
public CellDef setField(String field) {
this.field = field;
return this;
}
/** .
* @return
* @return CellDef
*/
public int getWidth() {
return width;
}
/** .
* @param width
* @return CellDef
*/
public CellDef setWidth(int width) {
this.width = width;
this.value = value;
return this;
}
/**, .
* @return ,
*/
public Object getValue() {
return value;
}
/**, .
* @param value ,
* @return CellDef
*/
public CellDef setValue(Object value) {
this.value = value;
return this;
}
}
}
Loading…
Cancel
Save