001// Generated from: ../../../../../../../../oscal/src/metaschema/oscal_metadata_metaschema.xml
002// Do not edit - changes will be lost when regenerated.
003package dev.metaschema.oscal.lib.model;
004
005import dev.metaschema.core.datatype.adapter.StringAdapter;
006import dev.metaschema.core.datatype.adapter.TokenAdapter;
007import dev.metaschema.core.model.IBoundObject;
008import dev.metaschema.core.model.IMetaschemaData;
009import dev.metaschema.core.model.JsonGroupAsBehavior;
010import dev.metaschema.core.model.constraint.IConstraint;
011import dev.metaschema.core.util.ObjectUtils;
012import dev.metaschema.databind.model.annotations.AllowedValue;
013import dev.metaschema.databind.model.annotations.AllowedValues;
014import dev.metaschema.databind.model.annotations.BoundField;
015import dev.metaschema.databind.model.annotations.BoundFlag;
016import dev.metaschema.databind.model.annotations.GroupAs;
017import dev.metaschema.databind.model.annotations.Matches;
018import dev.metaschema.databind.model.annotations.MetaschemaAssembly;
019import dev.metaschema.databind.model.annotations.ValueConstraints;
020import edu.umd.cs.findbugs.annotations.NonNull;
021import edu.umd.cs.findbugs.annotations.Nullable;
022import java.util.LinkedList;
023import java.util.List;
024import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
025import org.apache.commons.lang3.builder.ToStringStyle;
026
027/**
028 * A postal address for the location.
029 */
030@MetaschemaAssembly(
031    formalName = "Address",
032    description = "A postal address for the location.",
033    name = "address",
034    moduleClass = OscalMetadataModule.class
035)
036public class Address implements IBoundObject {
037  private final IMetaschemaData __metaschemaData;
038
039  /**
040   * Indicates the type of address.
041   */
042  @BoundFlag(
043      formalName = "Address Type",
044      description = "Indicates the type of address.",
045      name = "type",
046      typeAdapter = TokenAdapter.class,
047      valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(id = "oscal-metadata-address-location-type-values", level = IConstraint.Level.ERROR, allowOthers = true, values = {@AllowedValue(value = "home", description = "A home address."), @AllowedValue(value = "work", description = "A work address.")}))
048  )
049  private String _type;
050
051  /**
052   * A single line of an address.
053   */
054  @BoundField(
055      formalName = "Address line",
056      description = "A single line of an address.",
057      useName = "addr-line",
058      maxOccurs = -1,
059      groupAs = @GroupAs(name = "addr-lines", inJson = JsonGroupAsBehavior.LIST),
060      typeAdapter = StringAdapter.class
061  )
062  private List<String> _addrLines;
063
064  /**
065   * City, town or geographical region for the mailing address.
066   */
067  @BoundField(
068      formalName = "City",
069      description = "City, town or geographical region for the mailing address.",
070      useName = "city",
071      typeAdapter = StringAdapter.class
072  )
073  private String _city;
074
075  /**
076   * State, province or analogous geographical region for a mailing address.
077   */
078  @BoundField(
079      formalName = "State",
080      description = "State, province or analogous geographical region for a mailing address.",
081      useName = "state",
082      typeAdapter = StringAdapter.class
083  )
084  private String _state;
085
086  /**
087   * Postal or ZIP code for mailing address.
088   */
089  @BoundField(
090      formalName = "Postal Code",
091      description = "Postal or ZIP code for mailing address.",
092      useName = "postal-code",
093      typeAdapter = StringAdapter.class
094  )
095  private String _postalCode;
096
097  /**
098   * The ISO 3166-1 alpha-2 country code for the mailing address.
099   */
100  @BoundField(
101      formalName = "Country Code",
102      description = "The ISO 3166-1 alpha-2 country code for the mailing address.",
103      useName = "country",
104      typeAdapter = StringAdapter.class,
105      valueConstraints = @ValueConstraints(matches = @Matches(id = "oscal-metadata-location-address-country-regex", level = IConstraint.Level.ERROR, pattern = "[A-Z]{2}"))
106  )
107  private String _country;
108
109  /**
110   * Constructs a new {@code dev.metaschema.oscal.lib.model.Address} instance with no metadata.
111   */
112  public Address() {
113    this(null);
114  }
115
116  /**
117   * Constructs a new {@code dev.metaschema.oscal.lib.model.Address} instance with the specified metadata.
118   *
119   * @param data
120   *           the metaschema data, or {@code null} if none
121   */
122  public Address(IMetaschemaData data) {
123    this.__metaschemaData = data;
124  }
125
126  @Override
127  public IMetaschemaData getMetaschemaData() {
128    return __metaschemaData;
129  }
130
131  /**
132   * Get the "{@literal Address Type}".
133   *
134   * <p>
135   * Indicates the type of address.
136   *
137   * @return the type value, or {@code null} if not set
138   */
139  @Nullable
140  public String getType() {
141    return _type;
142  }
143
144  /**
145   * Set the "{@literal Address Type}".
146   *
147   * <p>
148   * Indicates the type of address.
149   *
150   * @param value
151   *           the type value to set, or {@code null} to clear
152   */
153  public void setType(@Nullable String value) {
154    _type = value;
155  }
156
157  /**
158   * Get the "{@literal Address line}".
159   *
160   * <p>
161   * A single line of an address.
162   *
163   * @return the addr-line value
164   */
165  @NonNull
166  public List<String> getAddrLines() {
167    if (_addrLines == null) {
168      _addrLines = new LinkedList<>();
169    }
170    return ObjectUtils.notNull(_addrLines);
171  }
172
173  /**
174   * Set the "{@literal Address line}".
175   *
176   * <p>
177   * A single line of an address.
178   *
179   * @param value
180   *           the addr-line value to set
181   */
182  public void setAddrLines(@NonNull List<String> value) {
183    _addrLines = value;
184  }
185
186  /**
187   * Add a new {@link String} item to the underlying collection.
188   * @param item the item to add
189   * @return {@code true}
190   */
191  public boolean addAddrLine(String item) {
192    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
193    if (_addrLines == null) {
194      _addrLines = new LinkedList<>();
195    }
196    return _addrLines.add(value);
197  }
198
199  /**
200   * Remove the first matching {@link String} item from the underlying collection.
201   * @param item the item to remove
202   * @return {@code true} if the item was removed or {@code false} otherwise
203   */
204  public boolean removeAddrLine(String item) {
205    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
206    return _addrLines != null && _addrLines.remove(value);
207  }
208
209  /**
210   * Get the "{@literal City}".
211   *
212   * <p>
213   * City, town or geographical region for the mailing address.
214   *
215   * @return the city value, or {@code null} if not set
216   */
217  @Nullable
218  public String getCity() {
219    return _city;
220  }
221
222  /**
223   * Set the "{@literal City}".
224   *
225   * <p>
226   * City, town or geographical region for the mailing address.
227   *
228   * @param value
229   *           the city value to set, or {@code null} to clear
230   */
231  public void setCity(@Nullable String value) {
232    _city = value;
233  }
234
235  /**
236   * Get the "{@literal State}".
237   *
238   * <p>
239   * State, province or analogous geographical region for a mailing address.
240   *
241   * @return the state value, or {@code null} if not set
242   */
243  @Nullable
244  public String getState() {
245    return _state;
246  }
247
248  /**
249   * Set the "{@literal State}".
250   *
251   * <p>
252   * State, province or analogous geographical region for a mailing address.
253   *
254   * @param value
255   *           the state value to set, or {@code null} to clear
256   */
257  public void setState(@Nullable String value) {
258    _state = value;
259  }
260
261  /**
262   * Get the "{@literal Postal Code}".
263   *
264   * <p>
265   * Postal or ZIP code for mailing address.
266   *
267   * @return the postal-code value, or {@code null} if not set
268   */
269  @Nullable
270  public String getPostalCode() {
271    return _postalCode;
272  }
273
274  /**
275   * Set the "{@literal Postal Code}".
276   *
277   * <p>
278   * Postal or ZIP code for mailing address.
279   *
280   * @param value
281   *           the postal-code value to set, or {@code null} to clear
282   */
283  public void setPostalCode(@Nullable String value) {
284    _postalCode = value;
285  }
286
287  /**
288   * Get the "{@literal Country Code}".
289   *
290   * <p>
291   * The ISO 3166-1 alpha-2 country code for the mailing address.
292   *
293   * @return the country value, or {@code null} if not set
294   */
295  @Nullable
296  public String getCountry() {
297    return _country;
298  }
299
300  /**
301   * Set the "{@literal Country Code}".
302   *
303   * <p>
304   * The ISO 3166-1 alpha-2 country code for the mailing address.
305   *
306   * @param value
307   *           the country value to set, or {@code null} to clear
308   */
309  public void setCountry(@Nullable String value) {
310    _country = value;
311  }
312
313  @Override
314  public String toString() {
315    return ObjectUtils.notNull(new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString());
316  }
317}