001package gov.nist.secauto.oscal.lib.model;
002
003import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValue;
004import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValues;
005import gov.nist.secauto.metaschema.binding.model.annotations.BoundField;
006import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag;
007import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
008import gov.nist.secauto.metaschema.binding.model.annotations.Matches;
009import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
010import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
011import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior;
012import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
013import gov.nist.secauto.metaschema.model.common.datatype.adapter.TokenAdapter;
014import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
015import java.lang.Override;
016import java.lang.String;
017import java.util.LinkedList;
018import java.util.List;
019import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
020import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
021
022/**
023 * A postal address for the location.
024 */
025@MetaschemaAssembly(
026    formalName = "Address",
027    description = "A postal address for the location.",
028    name = "address",
029    metaschema = OscalMetadataMetaschema.class
030)
031public class Address {
032  @BoundFlag(
033      formalName = "Address Type",
034      description = "Indicates the type of address.",
035      useName = "type",
036      typeAdapter = TokenAdapter.class
037  )
038  @ValueConstraints(
039      allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, allowOthers = true, values = {@AllowedValue(value = "home", description = "A home address."), @AllowedValue(value = "work", description = "A work address.")})
040  )
041  private String _type;
042
043  @BoundField(
044      formalName = "Address line",
045      description = "A single line of an address.",
046      useName = "addr-line",
047      maxOccurs = -1
048  )
049  @GroupAs(
050      name = "addr-lines",
051      inJson = JsonGroupAsBehavior.LIST
052  )
053  private List<String> _addrLines;
054
055  /**
056   * "City, town or geographical region for the mailing address."
057   */
058  @BoundField(
059      formalName = "City",
060      description = "City, town or geographical region for the mailing address.",
061      useName = "city"
062  )
063  private String _city;
064
065  /**
066   * "State, province or analogous geographical region for a mailing address."
067   */
068  @BoundField(
069      formalName = "State",
070      description = "State, province or analogous geographical region for a mailing address.",
071      useName = "state"
072  )
073  private String _state;
074
075  /**
076   * "Postal or ZIP code for mailing address."
077   */
078  @BoundField(
079      formalName = "Postal Code",
080      description = "Postal or ZIP code for mailing address.",
081      useName = "postal-code"
082  )
083  private String _postalCode;
084
085  /**
086   * "The ISO 3166-1 alpha-2 country code for the mailing address."
087   */
088  @BoundField(
089      formalName = "Country Code",
090      description = "The ISO 3166-1 alpha-2 country code for the mailing address.",
091      useName = "country"
092  )
093  @ValueConstraints(
094      matches = @Matches(level = IConstraint.Level.ERROR, pattern = "[A-Z]{2}")
095  )
096  private String _country;
097
098  public Address() {
099  }
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}