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