1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.moneywise.quicken.file;
18
19 import io.github.tonywasher.joceanus.oceanus.format.OceanusDataFormatter;
20 import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseTransCategory;
21
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.Iterator;
25 import java.util.List;
26
27
28
29
30
31
32 public class MoneyWiseQIFParentCategory
33 implements Comparable<MoneyWiseQIFParentCategory> {
34
35
36
37 private final MoneyWiseQIFEventCategory theSelf;
38
39
40
41
42 private final List<MoneyWiseQIFEventCategory> theChildren;
43
44
45
46
47
48
49
50 protected MoneyWiseQIFParentCategory(final MoneyWiseQIFFile pFile,
51 final MoneyWiseTransCategory pParent) {
52 this(new MoneyWiseQIFEventCategory(pFile, pParent));
53 }
54
55
56
57
58
59
60 protected MoneyWiseQIFParentCategory(final MoneyWiseQIFEventCategory pParent) {
61
62 theSelf = pParent;
63
64
65 theChildren = new ArrayList<>();
66 }
67
68 @Override
69 public String toString() {
70 return theSelf.toString();
71 }
72
73
74
75
76
77
78 protected int numChildren() {
79 return theChildren.size();
80 }
81
82
83
84
85
86
87 public MoneyWiseQIFEventCategory getParent() {
88 return theSelf;
89 }
90
91
92
93
94
95
96 public List<MoneyWiseQIFEventCategory> getChildren() {
97 return theChildren;
98 }
99
100
101
102
103
104
105 protected void registerChild(final MoneyWiseQIFEventCategory pChild) {
106
107 theChildren.add(pChild);
108 }
109
110
111
112
113 protected void sortChildren() {
114 Collections.sort(theChildren);
115 }
116
117
118
119
120
121
122
123 public void formatRecord(final OceanusDataFormatter pFormatter,
124 final StringBuilder pBuilder) {
125
126 theSelf.formatRecord(pFormatter, pBuilder);
127
128
129 final Iterator<MoneyWiseQIFEventCategory> myIterator = theChildren.iterator();
130 while (myIterator.hasNext()) {
131 final MoneyWiseQIFEventCategory myCategory = myIterator.next();
132
133
134 myCategory.formatRecord(pFormatter, pBuilder);
135 }
136 }
137
138 @Override
139 public boolean equals(final Object pThat) {
140
141 if (this == pThat) {
142 return true;
143 }
144 if (pThat == null) {
145 return false;
146 }
147
148
149 if (!getClass().equals(pThat.getClass())) {
150 return false;
151 }
152
153
154 final MoneyWiseQIFParentCategory myParent = (MoneyWiseQIFParentCategory) pThat;
155
156
157 if (!theSelf.equals(myParent.getParent())) {
158 return false;
159 }
160
161
162 return theChildren.equals(myParent.getChildren());
163 }
164
165 @Override
166 public int hashCode() {
167 final int myResult = MoneyWiseQIFFile.HASH_BASE * theSelf.hashCode();
168 return myResult + theChildren.hashCode();
169 }
170
171 @Override
172 public int compareTo(final MoneyWiseQIFParentCategory pThat) {
173 return theSelf.compareTo(pThat.getParent());
174 }
175 }