• R/O
  • SSH
  • HTTPS

aoiro: Commit


Commit MetaInfo

Révision53 (tree)
l'heure2020-06-29 10:07:56
Auteurhirukawa_ryo

Message de Log

* aoiro 0.7
JournalEntriesLoader.getJournalEntries 仕訳データの読み取りで貸借金額の不一致があっても例外をスローせずに読み取れるオプション(ignoreWarnings)を追加しました。
これはGUI実装で未完成・編集中の仕訳データをファイルから読み取るときに必要な機能です。

Change Summary

Modification

--- aoiro/trunk/src/main/java/net/osdn/aoiro/loader/yaml/AccountTitlesLoader.java (revision 52)
+++ aoiro/trunk/src/main/java/net/osdn/aoiro/loader/yaml/AccountTitlesLoader.java (revision 53)
@@ -36,21 +36,10 @@
3636 */
3737 public class AccountTitlesLoader {
3838
39+ private Path path;
3940
40- /** システムで使用する決算勘定 */
41- /*
42- private static Map<String, AccountTitle> settlementAccountTitleByDisplayName = new HashMap<>();
43-
44- static {
45- settlementAccountTitleByDisplayName.put(AccountTitle.INCOME_SUMMARY.getDisplayName(), AccountTitle.INCOME_SUMMARY);
46- settlementAccountTitleByDisplayName.put(AccountTitle.BALANCE.getDisplayName(), AccountTitle.BALANCE);
47- settlementAccountTitleByDisplayName.put(AccountTitle.RETAINED_EARNINGS.getDisplayName(), AccountTitle.RETAINED_EARNINGS);
48- settlementAccountTitleByDisplayName.put(AccountTitle.PRETAX_INCOME.getDisplayName(), AccountTitle.PRETAX_INCOME);
49- }
50- */
51-
5241 /** 勘定科目セット */
53- private Set<AccountTitle> accountTitles = new LinkedHashSet<>();
42+ private Set<AccountTitle> accountTitles;
5443
5544 /** 損益計算書(P/L)を作成するための構成情報 */
5645 private ProfitAndLossLayout plLayout = new ProfitAndLossLayout();
@@ -70,7 +59,17 @@
7059 put(AccountTitle.PRETAX_INCOME.getDisplayName(), AccountTitle.PRETAX_INCOME);
7160 }};
7261
73- public AccountTitlesLoader(Path path) throws IOException {
62+ public AccountTitlesLoader(Path path) {
63+ this.path = path;
64+ }
65+
66+ private void read() throws IOException {
67+ if(accountTitles != null) {
68+ return;
69+ }
70+
71+ accountTitles = new LinkedHashSet<>();
72+
7473 String yaml = AutoDetectReader.readAll(path);
7574 Object obj;
7675
@@ -619,7 +618,13 @@
619618 return valid;
620619 }
621620
622- public Set<AccountTitle> getAccountTitles() {
621+ /** 勘定科目のセットを取得します。
622+ *
623+ * @return 勘定科目のセット
624+ * @throws IOException I/Oエラーが発生した場合
625+ */
626+ public Set<AccountTitle> getAccountTitles() throws IOException {
627+ read();
623628 return accountTitles;
624629 }
625630
@@ -626,8 +631,10 @@
626631 /** 損益計算書の構成情報を返します。
627632 *
628633 * @return 損益計算書の構成情報
634+ * @throws IOException I/Oエラーが発生した場合
629635 */
630- public ProfitAndLossLayout getProfitAndLossLayout() {
636+ public ProfitAndLossLayout getProfitAndLossLayout() throws IOException {
637+ read();
631638 return plLayout;
632639 }
633640
@@ -634,8 +641,10 @@
634641 /** 貸借対照表の構成情報を返します。
635642 *
636643 * @return 貸借対照表の構成情報
644+ * @throws IOException I/Oエラーが発生した場合
637645 */
638- public BalanceSheetLayout getBalanceSheetLayout() {
646+ public BalanceSheetLayout getBalanceSheetLayout() throws IOException {
647+ read();
639648 return bsLayout;
640649 }
641650
@@ -642,8 +651,10 @@
642651 /** 社員資本等変動計算書の構成情報を返します。
643652 *
644653 * @return 社員資本等変動計算書の構成情報
654+ * @throws IOException I/Oエラーが発生した場合
645655 */
646- public StatementOfChangesInEquityLayout getStatementOfChangesInEquityLayout() {
656+ public StatementOfChangesInEquityLayout getStatementOfChangesInEquityLayout() throws IOException {
657+ read();
647658 return sceLayout;
648659 }
649660
@@ -679,7 +690,7 @@
679690
680691 /// save ///
681692
682- public static synchronized void save(Path file, Set<AccountTitle> accountTitles, ProfitAndLossLayout plLayout, BalanceSheetLayout bsLayout, StatementOfChangesInEquityLayout sceLayout) throws IOException {
693+ public static synchronized void write(Path file, Set<AccountTitle> accountTitles, ProfitAndLossLayout plLayout, BalanceSheetLayout bsLayout, StatementOfChangesInEquityLayout sceLayout) throws IOException {
683694 StringBuilder sb = new StringBuilder();
684695
685696 sb.append(getYaml(accountTitles));
--- aoiro/trunk/src/main/java/net/osdn/aoiro/loader/yaml/JournalEntriesLoader.java (revision 52)
+++ aoiro/trunk/src/main/java/net/osdn/aoiro/loader/yaml/JournalEntriesLoader.java (revision 53)
@@ -34,38 +34,43 @@
3434
3535 private static DateTimeFormatter dateParser = DateTimeFormatter.ofPattern("y-M-d");
3636
37+ private Path path;
3738 private Map<String, AccountTitle> accountTitleByDisplayName;
38- private List<JournalEntry> journals = new ArrayList<JournalEntry>();
3939
40- private List<String> warnings;
40+ public JournalEntriesLoader(Path path, Set<AccountTitle> accountTitles) {
41+ this.path = path;
4142
42- public JournalEntriesLoader(Path path, Set<AccountTitle> accountTitles) throws IOException {
43- this(path, accountTitles, null);
44- }
45-
46- public JournalEntriesLoader(Path path, Set<AccountTitle> accountTitles, List<String> warnings) throws IOException {
47- this.warnings = warnings;
48-
4943 this.accountTitleByDisplayName = new HashMap<String, AccountTitle>();
5044 for(AccountTitle accountTitle : accountTitles) {
5145 accountTitleByDisplayName.put(accountTitle.getDisplayName(), accountTitle);
5246 }
47+ }
5348
49+ /** 仕訳リストを取得します。
50+ *
51+ * @return 仕訳リスト
52+ * @throws IOException I/Oエラーが発生した場合
53+ */
54+ public List<JournalEntry> getJournalEntries() throws IOException {
55+ return getJournalEntries(false);
56+ }
57+
58+ /** 仕訳リストを取得します。
59+ *
60+ * @param ignoreWarnings 貸借金額の不一致など一部の警告を無視します。
61+ * @return 仕訳リスト
62+ * @throws IOException I/Oエラーが発生した場合
63+ */
64+ public List<JournalEntry> getJournalEntries(boolean ignoreWarnings) throws IOException {
5465 try {
55- new ItemReader(path).read();
66+ ItemReader reader = new ItemReader(path, ignoreWarnings);
67+ reader.read();
68+ return reader.journalEntries;
5669 } catch(YamlException e) {
5770 YamlBeansUtil.Message m = YamlBeansUtil.getMessage(e);
5871 throw error(" [エラー] " + path + " (" + m.getLine() + "行目, " + m.getColumn() + "桁目)\r\n " + m.getMessage());
5972 }
6073 }
61-
62- /** 仕訳リストを取得します。
63- *
64- * @return 仕訳リスト
65- */
66- public List<JournalEntry> getJournalEntries() {
67- return journals;
68- }
6974
7075 private static LocalDate parseDate(String s) {
7176 s = s.replace('/', '-')
@@ -93,10 +98,13 @@
9398 private class ItemReader extends YamlReader {
9499
95100 private Path path;
101+ private boolean ignoreWarnings;
102+ private List<JournalEntry> journalEntries = new ArrayList<>();
96103
97- public ItemReader(Path path) throws IOException {
104+ public ItemReader(Path path, boolean ignoreWarnings) throws IOException {
98105 super(AutoDetectReader.readAll(path));
99106 this.path = path;
107+ this.ignoreWarnings = ignoreWarnings;
100108 }
101109
102110 @SuppressWarnings("unchecked")
@@ -184,11 +192,14 @@
184192 creditors.add(new Creditor(accountTitle, amount));
185193 }
186194
187- if(debtorsAmount != creditorsAmount) {
188- throw error(" [エラー] " + path + " (" + line + "行目)\r\n 借方と貸方の金額が一致していません: 借方金額 " + debtorsAmount + ", 貸方金額 " + creditorsAmount);
195+ if(!ignoreWarnings) {
196+ // ignoreWarnings = true の場合、貸借金額の不一致はエラーとしません。
197+ if(debtorsAmount != creditorsAmount) {
198+ throw error(" [エラー] " + path + " (" + line + "行目)\r\n 借方と貸方の金額が一致していません: 借方金額 " + debtorsAmount + ", 貸方金額 " + creditorsAmount);
199+ }
189200 }
190201 JournalEntry entry = new JournalEntry(date, description, debtors, creditors);
191- journals.add(entry);
202+ journalEntries.add(entry);
192203 }
193204 return obj;
194205 }
@@ -208,7 +219,7 @@
208219
209220 /// save ///
210221
211- public static synchronized void save(Path file, List<JournalEntry> journalEntries) throws IOException {
222+ public static synchronized void write(Path file, List<JournalEntry> journalEntries) throws IOException {
212223 String yaml = getYaml(journalEntries);
213224
214225 Path tmpFile = null;
--- aoiro/trunk/src/main/java/net/osdn/aoiro/loader/yaml/ProportionalDivisionsLoader.java (revision 52)
+++ aoiro/trunk/src/main/java/net/osdn/aoiro/loader/yaml/ProportionalDivisionsLoader.java (revision 53)
@@ -27,35 +27,38 @@
2727 *
2828 */
2929 public class ProportionalDivisionsLoader {
30-
30+
31+ private Path path;
3132 private Map<String, AccountTitle> accountTitleByDisplayName;
32- private List<ProportionalDivision> proportionalDivisions = new ArrayList<ProportionalDivision>();
3333
34- public ProportionalDivisionsLoader(Path path, Set<AccountTitle> accountTitles) throws IOException {
34+ public ProportionalDivisionsLoader(Path path, Set<AccountTitle> accountTitles) {
35+ this.path = path;
36+
3537 this.accountTitleByDisplayName = new HashMap<String, AccountTitle>();
3638 for(AccountTitle accountTitle : accountTitles) {
3739 accountTitleByDisplayName.put(accountTitle.getDisplayName(), accountTitle);
3840 }
41+ }
3942
43+ /** 家事按分リストを取得します。
44+ *
45+ * @return 家事按分リスト
46+ */
47+ public List<ProportionalDivision> getProportionalDivisions() throws IOException {
4048 try {
41- new ItemReader(path).read();
49+ ItemReader reader = new ItemReader(path);
50+ reader.read();
51+ return reader.proportionalDivisions;
4252 } catch(YamlException e) {
4353 YamlBeansUtil.Message m = YamlBeansUtil.getMessage(e);
4454 throw error(" [エラー] " + path + " (" + m.getLine() + "行目, " + m.getColumn() + "桁目)\r\n " + m.getMessage());
4555 }
4656 }
47-
48- /** 家事按分リストを取得します。
49- *
50- * @return 家事按分リスト
51- */
52- public List<ProportionalDivision> getProportionalDivisions() {
53- return proportionalDivisions;
54- }
5557
5658 private class ItemReader extends YamlReader {
5759
5860 private Path path;
61+ private List<ProportionalDivision> proportionalDivisions = new ArrayList<>();
5962
6063 public ItemReader(Path path) throws IOException {
6164 super(AutoDetectReader.readAll(path));
@@ -114,7 +117,7 @@
114117
115118 /// save ///
116119
117- public static synchronized void save(Path file, List<ProportionalDivision> proportionalDivisions) throws IOException {
120+ public static synchronized void write(Path file, List<ProportionalDivision> proportionalDivisions) throws IOException {
118121 String yaml = getYaml(proportionalDivisions);
119122
120123 Path tmpFile = null;
Afficher sur ancien navigateur de dépôt.