1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.moneywise.tax.uk;
18
19 import io.github.tonywasher.joceanus.oceanus.decimal.OceanusRate;
20 import io.github.tonywasher.joceanus.oceanus.format.OceanusDataFormatter;
21 import io.github.tonywasher.joceanus.metis.field.MetisFieldItem;
22 import io.github.tonywasher.joceanus.metis.field.MetisFieldSet;
23 import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxBandSet;
24 import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxBandSet.MoneyWiseTaxBand;
25 import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxResource;
26
27 import java.util.Iterator;
28
29
30
31
32 public class MoneyWiseUKTaxBands
33 implements MetisFieldItem {
34
35
36
37 private static final MetisFieldSet<MoneyWiseUKTaxBands> FIELD_DEFS = MetisFieldSet.newFieldSet(MoneyWiseUKTaxBands.class);
38
39
40
41
42 static {
43 FIELD_DEFS.declareLocalField(MoneyWiseTaxResource.TAXBANDS_STANDARD, MoneyWiseUKTaxBands::getStandardSet);
44 FIELD_DEFS.declareLocalField(MoneyWiseTaxResource.TAXBANDS_HASLOTAXBAND, MoneyWiseUKTaxBands::hasLoTaxBand);
45 FIELD_DEFS.declareLocalField(MoneyWiseTaxResource.TAXBANDS_LOSAVINGS, MoneyWiseUKTaxBands::getLoSavings);
46 }
47
48
49
50
51 private final MoneyWiseTaxBandSet theStandard;
52
53
54
55
56 private final Boolean hasLoTaxBand;
57
58
59
60
61 private final MoneyWiseTaxBand theLoSavings;
62
63
64
65
66
67
68 protected MoneyWiseUKTaxBands(final MoneyWiseTaxBandSet pStandard) {
69 this(pStandard, Boolean.FALSE);
70 }
71
72
73
74
75
76
77
78 protected MoneyWiseUKTaxBands(final MoneyWiseTaxBandSet pStandard,
79 final Boolean pHasLoTaxBand) {
80 this(pStandard, pHasLoTaxBand, null);
81 }
82
83
84
85
86
87
88
89 protected MoneyWiseUKTaxBands(final MoneyWiseTaxBandSet pStandard,
90 final MoneyWiseTaxBand pLoSavings) {
91 this(pStandard, Boolean.FALSE, pLoSavings);
92 }
93
94
95
96
97
98
99
100
101 private MoneyWiseUKTaxBands(final MoneyWiseTaxBandSet pStandard,
102 final Boolean pHasLoTaxBand,
103 final MoneyWiseTaxBand pLoSavings) {
104 theStandard = pStandard;
105 hasLoTaxBand = pHasLoTaxBand;
106 theLoSavings = pLoSavings;
107 }
108
109
110
111
112
113
114 protected MoneyWiseUKTaxBands(final MoneyWiseUKTaxBands pSource) {
115 theStandard = new MoneyWiseTaxBandSet(pSource.getStandardSet());
116 hasLoTaxBand = pSource.hasLoTaxBand;
117 final MoneyWiseTaxBand mySavings = pSource.getLoSavings();
118 theLoSavings = mySavings == null
119 ? null
120 : new MoneyWiseTaxBand(mySavings);
121 }
122
123
124
125
126
127
128 public MoneyWiseTaxBandSet getStandardSet() {
129 return theStandard;
130 }
131
132
133
134
135
136
137 public Boolean hasLoTaxBand() {
138 return hasLoTaxBand;
139 }
140
141
142
143
144
145
146 public MoneyWiseTaxBand getLoSavings() {
147 return theLoSavings;
148 }
149
150
151
152
153
154
155 protected OceanusRate getBasicTaxRate() {
156 final Iterator<MoneyWiseTaxBand> myIterator = theStandard.iterator();
157 if (hasLoTaxBand && myIterator.hasNext()) {
158 myIterator.next();
159 }
160 return myIterator.hasNext()
161 ? myIterator.next().getRate()
162 : null;
163 }
164
165 @Override
166 public String formatObject(final OceanusDataFormatter pFormatter) {
167 return FIELD_DEFS.getName();
168 }
169
170 @Override
171 public MetisFieldSet<MoneyWiseUKTaxBands> getDataFieldSet() {
172 return FIELD_DEFS;
173 }
174 }