/
FileOptions.java
130 lines (109 loc) · 2.75 KB
/
FileOptions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package fr.ekinci.universalserializer.format.file;
import fr.ekinci.universalserializer.format.file.excel.ExcelFormat;
import org.apache.commons.csv.CSVFormat;
import java.time.format.DateTimeFormatter;
/**
* Immutable class for defining file options with a builder pattern
*
* @author Gokan EKINCI
*/
public class FileOptions {
private final String dateFormat;
private final String destinationPath;
private final boolean hasHeader;
// private final char separator; // For CSV
private final CSVFormat csvFormat;
private final ExcelFormat excelFormat;
private final int sheetIndex; // For Excel
private FileOptions(
String dateFormat,
String destinationPath,
boolean hasHeader,
CSVFormat csvFormat,
ExcelFormat excelFormat,
int sheetIndex
) {
this.dateFormat = dateFormat;
this.destinationPath = destinationPath;
this.hasHeader = hasHeader;
this.csvFormat = csvFormat;
this.excelFormat = excelFormat;
this.sheetIndex = sheetIndex;
}
public String dateFormat() {
return dateFormat;
}
public String destinationPath() {
return destinationPath;
}
public boolean hasHeader() {
return hasHeader;
}
public CSVFormat csvFormat() {
return csvFormat;
}
public ExcelFormat excelFormat() {
return excelFormat;
}
public int sheetIndex() {
return sheetIndex;
}
public static FileOptionsBuilder builder() {
return new FileOptionsBuilder();
}
public static class FileOptionsBuilder {
private String dateFormat;
private String destinationPath;
private boolean hasHeader;
private CSVFormat csvFormat;
private ExcelFormat excelFormat;
private int sheetIndex;
private FileOptionsBuilder() {
dateFormat = "yyyy-MM-dd HH:mm:ss";
destinationPath = null; // If null then temp file
hasHeader = false;
csvFormat = CSVFormat.DEFAULT;
excelFormat = ExcelFormat.XLSX;
sheetIndex = 0;
}
public FileOptionsBuilder dateFormat(String dateFormat) {
this.dateFormat = dateFormat;
return this;
}
public FileOptionsBuilder destinationPath(String destinationPath) {
this.destinationPath = destinationPath;
return this;
}
public FileOptionsBuilder hasHeader(boolean hasHeader) {
this.hasHeader = hasHeader;
return this;
}
public FileOptionsBuilder csvFormat(CSVFormat csvFormat) {
this.csvFormat = csvFormat;
return this;
}
public FileOptionsBuilder excelFormat(ExcelFormat excelFormat) {
this.excelFormat = excelFormat;
return this;
}
public FileOptionsBuilder sheetIndex(int sheetIndex) {
this.sheetIndex = sheetIndex;
return this;
}
/**
* Build operation
*
* @return FIleOptions object
*/
public FileOptions build() {
return new FileOptions(
dateFormat,
destinationPath,
hasHeader,
csvFormat,
excelFormat,
sheetIndex
);
}
}
}