hi, all
   I found that all the withXXX methods in CSVFomat class need to call the 
constructor to generate a new CSVFomat object.
Once a new format attribute is added, you need to change the call of nearly 30 
constructors.May be we can add
a map to record all the attributes of CSVFormat class and a constructor, the 
input parameter is map, and the withXXX methods
call the constructor using the map as input parameter. You only need to modify 
the attributes of the map that need to be modified.
Then when we add a new attribute to CSVFomat, we do not need to modify the 
withXXX methods in so many places.


The following is the demo:


private CSVFomat(HashMap<String, Object> formatAttrMap) {
    this.delimiter = formatAttrMap.get("delimiter ").toString().charAt(0);
    //todo add other attributes
    this. formatAttrMap = (HashMap<String, Object>) formatAttrMap.clone();
}
private HashMap<String, Object> getFormatAttrMap() {
    return this. formatAttrMap ;
}
public CSVFormat withDelimiter(final char delimiter) {
    if (isLineBreak(delimiter)) {
        throw new IllegalArgumentException("The delimiter cannot be a line 
break");
    }
    HashMap<String, Object> formatAttrMap = getFormatAttrMap();
    formatAttrMap.put("delimiter", delimiter);
    return new CSVFormat(formatAttrMap);
} 



Reply via email to