summaryrefslogtreecommitdiff
path: root/src/main/java/com/p4square/ccbapi/model/Address.java
blob: 9bbd6e3249d2557ad809db45b7e472a033d3dc03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.p4square.ccbapi.model;

import javax.xml.bind.annotation.*;

/**
 * Representation of a United States postal address.
 */
@XmlRootElement(name="address")
@XmlAccessorType(XmlAccessType.NONE)
public class Address {
    @XmlType(namespace="Address")
    public enum Type {
        @XmlEnumValue("mailing") MAILING,
        @XmlEnumValue("home") HOME,
        @XmlEnumValue("work") WORK,
        @XmlEnumValue("other") OTHER;
    }

    @XmlAttribute(name="type")
    private Type type;

    @XmlElement(name="street_address")
    private String streetAddress;

    @XmlElement(name="city")
    private String city;

    @XmlElement(name="state")
    private String state;

    @XmlElement(name="zip")
    private String zip;

    @XmlElement(name="country")
    private Country country;

    @XmlElement(name="line_1")
    private String line_1;

    @XmlElement(name="line_2")
    private String line_2;

    @XmlElement(name="latitude")
    private String latitude;

    @XmlElement(name="longitude")
    private String longitude;

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public String getStreetAddress() {
        return streetAddress;
    }

    public void setStreetAddress(String streetAddress) {
        this.streetAddress = streetAddress;
        updateAddressLines();
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
        updateAddressLines();
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        if (state.length() < 2 || state.length() > 3) {
            throw new IllegalArgumentException("Invalid state code.");
        }
        this.state = state.toUpperCase();
        updateAddressLines();
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
        updateAddressLines();
    }

    public Country getCountry() {
        return country;
    }

    public void setCountry(Country country) {
        this.country = country;
        updateAddressLines();
    }

    public String getLine_1() {
        return line_1;
    }

    public String getLine_2() {
        return line_2;
    }

    public String getLatitude() {
        return latitude;
    }

    public String getLongitude() {
        return longitude;
    }

    private void updateAddressLines() {
        this.line_1 = streetAddress;
        this.line_2 = String.format("%s, %s %s", city, state, zip);
    }
}