From e3a343804657849d43a3f4585c17dfc74c0ee177 Mon Sep 17 00:00:00 2001 From: Yen kuang Chen Date: Tue, 20 Sep 2022 18:10:32 +0800 Subject: [PATCH] update: update singleton instance --- .../{Crawler_jar2.xml => Crawler_jar.xml} | 2 +- .idea/compiler.xml | 4 ++-- .idea/modules.xml | 2 +- src/main/java/config/EnvironmentVariable.java | 10 ++++++---- src/main/java/module/DataProcessor.java | 6 ++++++ src/main/java/module/ExcelManipulate.java | 14 +++++++++----- 6 files changed, 25 insertions(+), 13 deletions(-) rename .idea/artifacts/{Crawler_jar2.xml => Crawler_jar.xml} (99%) diff --git a/.idea/artifacts/Crawler_jar2.xml b/.idea/artifacts/Crawler_jar.xml similarity index 99% rename from .idea/artifacts/Crawler_jar2.xml rename to .idea/artifacts/Crawler_jar.xml index 7f74e75..35dec54 100644 --- a/.idea/artifacts/Crawler_jar2.xml +++ b/.idea/artifacts/Crawler_jar.xml @@ -2,7 +2,7 @@ $PROJECT_DIR$/out/artifacts/Crawler_jar - + diff --git a/.idea/compiler.xml b/.idea/compiler.xml index ce07bb0..80dd23a 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -6,11 +6,11 @@ - + - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 1be9dbb..5bbca27 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/src/main/java/config/EnvironmentVariable.java b/src/main/java/config/EnvironmentVariable.java index 14917f0..9805d22 100644 --- a/src/main/java/config/EnvironmentVariable.java +++ b/src/main/java/config/EnvironmentVariable.java @@ -9,18 +9,20 @@ import java.util.Map; public class EnvironmentVariable { + private static EnvironmentVariable uniqueInstance; InputStream inputStream; - static EnvironmentVariable env; public Map 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; } } diff --git a/src/main/java/module/DataProcessor.java b/src/main/java/module/DataProcessor.java index b13a6e7..4b1af09 100644 --- a/src/main/java/module/DataProcessor.java +++ b/src/main/java/module/DataProcessor.java @@ -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(); } diff --git a/src/main/java/module/ExcelManipulate.java b/src/main/java/module/ExcelManipulate.java index ffb3b26..29c7347 100644 --- a/src/main/java/module/ExcelManipulate.java +++ b/src/main/java/module/ExcelManipulate.java @@ -19,7 +19,7 @@ import org.apache.poi.ss.util.CellRangeAddress; public class ExcelManipulate { - + private static ExcelManipulate excelManipulate; static Workbook wb = new HSSFWorkbook(); private ExcelManipulate() { @@ -27,7 +27,11 @@ private ExcelManipulate() { } public static ExcelManipulate getInstance() { - return new ExcelManipulate(); + if (excelManipulate == null) { + excelManipulate = new ExcelManipulate(); + } + + return excelManipulate; } public void saveDataInExcel(List list, String path) throws IOException { @@ -51,7 +55,7 @@ private Sheet createFirstSheet(List 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); @@ -99,7 +103,7 @@ private Sheet createSecondSheet(List 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)); @@ -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));