Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: update singleton instance #11

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/main/java/config/EnvironmentVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
import java.util.Map;

public class EnvironmentVariable {
private static EnvironmentVariable uniqueInstance;
InputStream inputStream;
static EnvironmentVariable env;
public Map<String, Object> data;

public EnvironmentVariable() throws FileNotFoundException {
private EnvironmentVariable() throws FileNotFoundException {
this.inputStream = new FileInputStream("config.yml");
Yaml yaml = new Yaml();
this.data = yaml.load(inputStream);
}

public static EnvironmentVariable getInstance() throws FileNotFoundException {
env = new EnvironmentVariable();
return env;
if (uniqueInstance == null) {
uniqueInstance = new EnvironmentVariable();
}
return uniqueInstance;
}
}
6 changes: 6 additions & 0 deletions src/main/java/module/DataProcessor.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package module;

import config.EnvironmentVariable;

import java.io.FileNotFoundException;
import java.util.ArrayList;

public class DataProcessor {
private static DataProcessor uniqueInstance;

private DataProcessor() {
}

public static DataProcessor getInstance() {
if (uniqueInstance == null) {
uniqueInstance = new DataProcessor();
}

return new DataProcessor();
}

Expand Down
14 changes: 9 additions & 5 deletions src/main/java/module/ExcelManipulate.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@
import org.apache.poi.ss.util.CellRangeAddress;

public class ExcelManipulate {

private static ExcelManipulate excelManipulate;
static Workbook wb = new HSSFWorkbook();

private ExcelManipulate() {

}

public static ExcelManipulate getInstance() {
return new ExcelManipulate();
if (excelManipulate == null) {
excelManipulate = new ExcelManipulate();
}

return excelManipulate;
}

public void saveDataInExcel(List<String> list, String path) throws IOException {
Expand All @@ -51,7 +55,7 @@ private Sheet createFirstSheet(List<String> list) throws FileNotFoundException {
Cell title_cell = title_row.createCell(0);

// Set up the header
String headers[] = new String[] {"報帳條碼", "經費或計畫名稱", "計畫代碼", "經費別", "金額", "報帳日", "傳票號碼",
String headers[] = new String[]{"報帳條碼", "經費或計畫名稱", "計畫代碼", "經費別", "金額", "報帳日", "傳票號碼",
"付款資料", "報帳ID", "列印次數", "受款人", "備註", "稅前金額"};

Row header_row = first.createRow(1);
Expand Down Expand Up @@ -99,7 +103,7 @@ private Sheet createSecondSheet(List<String> list) {
title_row.setHeight((short) (40 * 20));
Cell title_cell = title_row.createCell(0);

String headers[] = new String[] {"報帳條碼", "經費或計畫名稱", "計畫代碼", "經費別", "金額", "報帳日", "傳票號碼",
String headers[] = new String[]{"報帳條碼", "經費或計畫名稱", "計畫代碼", "經費別", "金額", "報帳日", "傳票號碼",
"付款資料", "報帳ID", "列印次數", "受款人", "備註"};
Row header_row = second.createRow(1);
header_row.setHeight((short) (20 * 24));
Expand Down Expand Up @@ -135,7 +139,7 @@ private Sheet createThirdSheet(Sheet first, Sheet second) {
title_row.setHeight((short) (40 * 20));
Cell title_cell = title_row.createCell(0);

String headers[] = new String[] {"報帳條碼", "經費或計畫名稱", "計畫代碼", "經費別", "金額", "報帳日", "傳票號碼",
String headers[] = new String[]{"報帳條碼", "經費或計畫名稱", "計畫代碼", "經費別", "金額", "報帳日", "傳票號碼",
"付款資料", "報帳ID", "列印次數", "受款人", "備註"};
Row header_row = third.createRow(1);
header_row.setHeight((short) (20 * 24));
Expand Down