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