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