001/*
002 * Copyright 2010-2014 Ning, Inc.
003 * Copyright 2014-2015 The Billing Project, LLC
004 *
005 * The Billing Project licenses this file to you under the Apache License, version 2.0
006 * (the "License"); you may not use this file except in compliance with the
007 * License.  You may obtain a copy of the License at:
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
014 * License for the specific language governing permissions and limitations
015 * under the License.
016 */
017
018package com.ning.billing.recurly.model;
019
020import java.util.Map;
021import com.google.common.base.Objects;
022
023import javax.annotation.Nullable;
024import javax.xml.bind.annotation.XmlElement;
025
026import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
027
028@JsonIgnoreProperties(ignoreUnknown = true)
029public class RecurlyUnitCurrency {
030
031    // United States Dollars
032    @XmlElement(name = "USD")
033    private Integer unitAmountUSD;
034
035    // Australian Dollars
036    @XmlElement(name = "AUD")
037    private Integer unitAmountAUD;
038    
039    @XmlElement(name = "JPY")
040    private Integer unitAmountJPY;
041
042    // Canadian Dollars
043    @XmlElement(name = "CAD")
044    private Integer unitAmountCAD;
045
046    // Euros
047    @XmlElement(name = "EUR")
048    private Integer unitAmountEUR;
049
050    // British Pounds
051    @XmlElement(name = "GBP")
052    private Integer unitAmountGBP;
053
054    // Czech Korunas
055    @XmlElement(name = "CZK")
056    private Integer unitAmountCZK;
057
058    // Danish Krones
059    @XmlElement(name = "DKK")
060    private Integer unitAmountDKK;
061
062    // Hungarian Forints
063    @XmlElement(name = "HUF")
064    private Integer unitAmountHUF;
065
066    // Indian Rupees
067    @XmlElement(name = "INR")
068    private Integer unitAmountINR;
069
070    // Norwegian Krones
071    @XmlElement(name = "NOK")
072    private Integer unitAmountNOK;
073
074    // New Zealand Dollars
075    @XmlElement(name = "NZD")
076    private Integer unitAmountNZD;
077
078    // Polish Zloty
079    @XmlElement(name = "PLN")
080    private Integer unitAmountPLN;
081
082    // Singapore Dollars
083    @XmlElement(name = "SGD")
084    private Integer unitAmountSGD;
085
086    // Swedish Kronas
087    @XmlElement(name = "SEK")
088    private Integer unitAmountSEK;
089
090    // Swiss Francs
091    @XmlElement(name = "CHF")
092    private Integer unitAmountCHF;
093
094    // South African Rand
095    @XmlElement(name = "ZAR")
096    private Integer unitAmountZAR;
097
098    public static RecurlyUnitCurrency build(@Nullable final Object unitAmountInCents) {
099        if (RecurlyObject.isNull(unitAmountInCents)) {
100            return null;
101        }
102
103        if (unitAmountInCents instanceof RecurlyUnitCurrency) {
104            return (RecurlyUnitCurrency) unitAmountInCents;
105        }
106
107        final RecurlyUnitCurrency recurlyUnitCurrency = new RecurlyUnitCurrency();
108
109        if (unitAmountInCents instanceof Map) {
110            final Map amounts = (Map) unitAmountInCents;
111
112            recurlyUnitCurrency.setUnitAmountUSD(amounts.get("USD"));
113            recurlyUnitCurrency.setUnitAmountAUD(amounts.get("AUD"));
114            recurlyUnitCurrency.setUnitAmountCAD(amounts.get("CAD"));
115            recurlyUnitCurrency.setUnitAmountEUR(amounts.get("EUR"));
116            recurlyUnitCurrency.setUnitAmountGBP(amounts.get("GBP"));
117            recurlyUnitCurrency.setUnitAmountCZK(amounts.get("CZK"));
118            recurlyUnitCurrency.setUnitAmountDKK(amounts.get("DKK"));
119            recurlyUnitCurrency.setUnitAmountHUF(amounts.get("HUF"));
120            recurlyUnitCurrency.setUnitAmountNOK(amounts.get("NOK"));
121            recurlyUnitCurrency.setUnitAmountNZD(amounts.get("NZD"));
122            recurlyUnitCurrency.setUnitAmountPLN(amounts.get("PLN"));
123            recurlyUnitCurrency.setUnitAmountSGD(amounts.get("SGD"));
124            recurlyUnitCurrency.setUnitAmountSEK(amounts.get("SEK"));
125            recurlyUnitCurrency.setUnitAmountCHF(amounts.get("CHF"));
126            recurlyUnitCurrency.setUnitAmountZAR(amounts.get("ZAR"));
127            recurlyUnitCurrency.setUnitAmountJPY(amounts.get("JPY"));
128            recurlyUnitCurrency.setUnitAmountINR(amounts.get("INR"));
129        }
130
131        return recurlyUnitCurrency;
132    }
133
134    public Integer getUnitAmountUSD() {
135        return unitAmountUSD;
136    }
137
138    public void setUnitAmountUSD(final Object unitAmountUSD) {
139        this.unitAmountUSD = RecurlyObject.integerOrNull(unitAmountUSD);
140    }
141
142    public Integer getUnitAmountAUD() {
143        return unitAmountAUD;
144    }
145
146    public void setUnitAmountAUD(final Object unitAmountAUD) {
147        this.unitAmountAUD = RecurlyObject.integerOrNull(unitAmountAUD);
148    }
149
150    public Integer getUnitAmountCAD() {
151        return unitAmountCAD;
152    }
153
154    public void setUnitAmountCAD(final Object unitAmountCAD) {
155        this.unitAmountCAD = RecurlyObject.integerOrNull(unitAmountCAD);
156    }
157
158    public Integer getUnitAmountEUR() {
159        return unitAmountEUR;
160    }
161
162    public void setUnitAmountEUR(final Object unitAmountEUR) {
163        this.unitAmountEUR = RecurlyObject.integerOrNull(unitAmountEUR);
164    }
165
166    public Integer getUnitAmountGBP() {
167        return unitAmountGBP;
168    }
169
170    public void setUnitAmountGBP(final Object unitAmountGBP) {
171        this.unitAmountGBP = RecurlyObject.integerOrNull(unitAmountGBP);
172    }
173
174    public Integer getUnitAmountCZK() {
175        return unitAmountCZK;
176    }
177
178    public void setUnitAmountCZK(final Object unitAmountCZK) {
179        this.unitAmountCZK = RecurlyObject.integerOrNull(unitAmountCZK);
180    }
181
182    public Integer getUnitAmountDKK() {
183        return unitAmountDKK;
184    }
185
186    public void setUnitAmountDKK(final Object unitAmountDKK) {
187        this.unitAmountDKK = RecurlyObject.integerOrNull(unitAmountDKK);
188    }
189
190    public Integer getUnitAmountHUF() {
191        return unitAmountHUF;
192    }
193
194    public void setUnitAmountHUF(final Object unitAmountHUF) {
195        this.unitAmountHUF = RecurlyObject.integerOrNull(unitAmountHUF);
196    }
197
198    public Integer getUnitAmountINR() {
199        return unitAmountINR;
200    }
201
202    public void setUnitAmountINR(final Object unitAmountINR) {
203        this.unitAmountINR = RecurlyObject.integerOrNull(unitAmountINR);
204    }
205
206    public Integer getUnitAmountNOK() {
207        return unitAmountNOK;
208    }
209
210    public void setUnitAmountNOK(final Object unitAmountNOK) {
211        this.unitAmountNOK = RecurlyObject.integerOrNull(unitAmountNOK);
212    }
213    
214    public Integer getUnitAmountJPY() {
215        return unitAmountJPY;
216    }
217
218    public void setUnitAmountJPY(final Object unitAmountJPY) {
219        this.unitAmountJPY = RecurlyObject.integerOrNull(unitAmountJPY);
220    }
221    
222    public Integer getUnitAmountNZD() {
223        return unitAmountNZD;
224    }
225
226    public void setUnitAmountNZD(final Object unitAmountNZD) {
227        this.unitAmountNZD = RecurlyObject.integerOrNull(unitAmountNZD);
228    }
229
230    public Integer getUnitAmountPLN() {
231        return unitAmountPLN;
232    }
233
234    public void setUnitAmountPLN(final Object unitAmountPLN) {
235        this.unitAmountPLN = RecurlyObject.integerOrNull(unitAmountPLN);
236    }
237
238    public Integer getUnitAmountSGD() {
239        return unitAmountSGD;
240    }
241
242    public void setUnitAmountSGD(final Object unitAmountSGD) {
243        this.unitAmountSGD = RecurlyObject.integerOrNull(unitAmountSGD);
244    }
245
246    public Integer getUnitAmountSEK() {
247        return unitAmountSEK;
248    }
249
250    public void setUnitAmountSEK(final Object unitAmountSEK) {
251        this.unitAmountSEK = RecurlyObject.integerOrNull(unitAmountSEK);
252    }
253
254    public Integer getUnitAmountCHF() {
255        return unitAmountCHF;
256    }
257
258    public void setUnitAmountCHF(final Object unitAmountCHF) {
259        this.unitAmountCHF = RecurlyObject.integerOrNull(unitAmountCHF);
260    }
261
262    public Integer getUnitAmountZAR() {
263        return unitAmountZAR;
264    }
265
266    public void setUnitAmountZAR(final Object unitAmountZAR) {
267        this.unitAmountZAR = RecurlyObject.integerOrNull(unitAmountZAR);
268    }
269
270    @Override
271    public String toString() {
272        final StringBuilder sb = new StringBuilder();
273        sb.append("RecurlyUnitCurrency");
274        sb.append("{unitAmountUSD=").append(unitAmountUSD);
275        sb.append(", unitAmountAUD=").append(unitAmountAUD);
276        sb.append(", unitAmountCAD=").append(unitAmountCAD);
277        sb.append(", unitAmountEUR=").append(unitAmountEUR);
278        sb.append(", unitAmountGBP=").append(unitAmountGBP);
279        sb.append(", unitAmountCZK=").append(unitAmountCZK);
280        sb.append(", unitAmountDKK=").append(unitAmountDKK);
281        sb.append(", unitAmountHUF=").append(unitAmountHUF);
282        sb.append(", unitAmountNOK=").append(unitAmountNOK);
283        sb.append(", unitAmountNZD=").append(unitAmountNZD);
284        sb.append(", unitAmountPLN=").append(unitAmountPLN);
285        sb.append(", unitAmountSGD=").append(unitAmountSGD);
286        sb.append(", unitAmountSEK=").append(unitAmountSEK);
287        sb.append(", unitAmountCHF=").append(unitAmountCHF);
288        sb.append(", unitAmountZAR=").append(unitAmountZAR);
289        sb.append(", unitAmountJPY=").append(unitAmountJPY);
290        sb.append(", unitAmountINR=").append(unitAmountINR);
291        sb.append('}');
292        return sb.toString();
293    }
294
295    @Override
296    public boolean equals(final Object o) {
297        if (this == o) return true;
298        if (o == null || getClass() != o.getClass()) return false;
299
300        final RecurlyUnitCurrency that = (RecurlyUnitCurrency) o;
301
302        if (unitAmountAUD != null ? !unitAmountAUD.equals(that.unitAmountAUD) : that.unitAmountAUD != null) {
303            return false;
304        }
305        if (unitAmountCAD != null ? !unitAmountCAD.equals(that.unitAmountCAD) : that.unitAmountCAD != null) {
306            return false;
307        }
308        if (unitAmountCHF != null ? !unitAmountCHF.equals(that.unitAmountCHF) : that.unitAmountCHF != null) {
309            return false;
310        }
311        if (unitAmountCZK != null ? !unitAmountCZK.equals(that.unitAmountCZK) : that.unitAmountCZK != null) {
312            return false;
313        }
314        if (unitAmountDKK != null ? !unitAmountDKK.equals(that.unitAmountDKK) : that.unitAmountDKK != null) {
315            return false;
316        }
317        if (unitAmountEUR != null ? !unitAmountEUR.equals(that.unitAmountEUR) : that.unitAmountEUR != null) {
318            return false;
319        }
320        if (unitAmountGBP != null ? !unitAmountGBP.equals(that.unitAmountGBP) : that.unitAmountGBP != null) {
321            return false;
322        }
323        if (unitAmountHUF != null ? !unitAmountHUF.equals(that.unitAmountHUF) : that.unitAmountHUF != null) {
324            return false;
325        }
326        if (unitAmountNOK != null ? !unitAmountNOK.equals(that.unitAmountNOK) : that.unitAmountNOK != null) {
327            return false;
328        }
329        if (unitAmountNZD != null ? !unitAmountNZD.equals(that.unitAmountNZD) : that.unitAmountNZD != null) {
330            return false;
331        }
332        if (unitAmountPLN != null ? !unitAmountPLN.equals(that.unitAmountPLN) : that.unitAmountPLN != null) {
333            return false;
334        }
335        if (unitAmountSEK != null ? !unitAmountSEK.equals(that.unitAmountSEK) : that.unitAmountSEK != null) {
336            return false;
337        }
338        if (unitAmountSGD != null ? !unitAmountSGD.equals(that.unitAmountSGD) : that.unitAmountSGD != null) {
339            return false;
340        }
341        if (unitAmountUSD != null ? !unitAmountUSD.equals(that.unitAmountUSD) : that.unitAmountUSD != null) {
342            return false;
343        }
344        if (unitAmountZAR != null ? !unitAmountZAR.equals(that.unitAmountZAR) : that.unitAmountZAR != null) {
345            return false;
346        }
347        if (unitAmountJPY != null ? !unitAmountJPY.equals(that.unitAmountJPY) : that.unitAmountJPY != null) {
348            return false;
349        }
350        if (unitAmountINR != null ? !unitAmountINR.equals(that.unitAmountINR) : that.unitAmountINR != null) {
351            return false;
352        }
353        return true;
354    }
355
356    @Override
357    public int hashCode() {
358        return Objects.hashCode(
359                unitAmountUSD,
360                unitAmountCAD,
361                unitAmountAUD,
362                unitAmountEUR,
363                unitAmountGBP,
364                unitAmountCZK,
365                unitAmountDKK,
366                unitAmountHUF,
367                unitAmountNOK,
368                unitAmountNZD,
369                unitAmountPLN,
370                unitAmountSGD,
371                unitAmountSEK,
372                unitAmountCHF,
373                unitAmountZAR,
374                unitAmountJPY,
375                unitAmountINR
376        );
377    }
378}