View Javadoc
1   package gov.nist.secauto.oscal.lib.model;
2   
3   import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValue;
4   import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValues;
5   import gov.nist.secauto.metaschema.binding.model.annotations.BoundField;
6   import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag;
7   import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
8   import gov.nist.secauto.metaschema.binding.model.annotations.Matches;
9   import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
10  import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
11  import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior;
12  import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
13  import gov.nist.secauto.metaschema.model.common.datatype.adapter.TokenAdapter;
14  import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
15  import java.lang.Override;
16  import java.lang.String;
17  import java.util.LinkedList;
18  import java.util.List;
19  import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
20  import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
21  
22  /**
23   * A postal address for the location.
24   */
25  @MetaschemaAssembly(
26      formalName = "Address",
27      description = "A postal address for the location.",
28      name = "address",
29      metaschema = OscalMetadataMetaschema.class
30  )
31  public class Address {
32    @BoundFlag(
33        formalName = "Address Type",
34        description = "Indicates the type of address.",
35        useName = "type",
36        typeAdapter = TokenAdapter.class
37    )
38    @ValueConstraints(
39        allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, allowOthers = true, values = {@AllowedValue(value = "home", description = "A home address."), @AllowedValue(value = "work", description = "A work address.")})
40    )
41    private String _type;
42  
43    @BoundField(
44        formalName = "Address line",
45        description = "A single line of an address.",
46        useName = "addr-line",
47        maxOccurs = -1
48    )
49    @GroupAs(
50        name = "addr-lines",
51        inJson = JsonGroupAsBehavior.LIST
52    )
53    private List<String> _addrLines;
54  
55    /**
56     * "City, town or geographical region for the mailing address."
57     */
58    @BoundField(
59        formalName = "City",
60        description = "City, town or geographical region for the mailing address.",
61        useName = "city"
62    )
63    private String _city;
64  
65    /**
66     * "State, province or analogous geographical region for a mailing address."
67     */
68    @BoundField(
69        formalName = "State",
70        description = "State, province or analogous geographical region for a mailing address.",
71        useName = "state"
72    )
73    private String _state;
74  
75    /**
76     * "Postal or ZIP code for mailing address."
77     */
78    @BoundField(
79        formalName = "Postal Code",
80        description = "Postal or ZIP code for mailing address.",
81        useName = "postal-code"
82    )
83    private String _postalCode;
84  
85    /**
86     * "The ISO 3166-1 alpha-2 country code for the mailing address."
87     */
88    @BoundField(
89        formalName = "Country Code",
90        description = "The ISO 3166-1 alpha-2 country code for the mailing address.",
91        useName = "country"
92    )
93    @ValueConstraints(
94        matches = @Matches(level = IConstraint.Level.ERROR, pattern = "[A-Z]{2}")
95    )
96    private String _country;
97  
98    public Address() {
99    }
100 
101   public String getType() {
102     return _type;
103   }
104 
105   public void setType(String value) {
106     _type = value;
107   }
108 
109   public List<String> getAddrLines() {
110     return _addrLines;
111   }
112 
113   public void setAddrLines(List<String> value) {
114     _addrLines = value;
115   }
116 
117   /**
118    * Add a new {@link String} item to the underlying collection.
119    * @param item the item to add
120    * @return {@code true}
121    */
122   public boolean addAddrLine(String item) {
123     String value = ObjectUtils.requireNonNull(item,"item cannot be null");
124     if (_addrLines == null) {
125       _addrLines = new LinkedList<>();
126     }
127     return _addrLines.add(value);
128   }
129 
130   /**
131    * Remove the first matching {@link String} item from the underlying collection.
132    * @param item the item to remove
133    * @return {@code true} if the item was removed or {@code false} otherwise
134    */
135   public boolean removeAddrLine(String item) {
136     String value = ObjectUtils.requireNonNull(item,"item cannot be null");
137     return _addrLines == null ? false : _addrLines.remove(value);
138   }
139 
140   public String getCity() {
141     return _city;
142   }
143 
144   public void setCity(String value) {
145     _city = value;
146   }
147 
148   public String getState() {
149     return _state;
150   }
151 
152   public void setState(String value) {
153     _state = value;
154   }
155 
156   public String getPostalCode() {
157     return _postalCode;
158   }
159 
160   public void setPostalCode(String value) {
161     _postalCode = value;
162   }
163 
164   public String getCountry() {
165     return _country;
166   }
167 
168   public void setCountry(String value) {
169     _country = value;
170   }
171 
172   @Override
173   public String toString() {
174     return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
175   }
176 }