Address.java

package gov.nist.secauto.oscal.lib.model;

import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValue;
import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValues;
import gov.nist.secauto.metaschema.binding.model.annotations.BoundField;
import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag;
import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
import gov.nist.secauto.metaschema.binding.model.annotations.Matches;
import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior;
import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
import gov.nist.secauto.metaschema.model.common.datatype.adapter.TokenAdapter;
import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
import java.lang.Override;
import java.lang.String;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

/**
 * A postal address for the location.
 */
@MetaschemaAssembly(
    formalName = "Address",
    description = "A postal address for the location.",
    name = "address",
    metaschema = OscalMetadataMetaschema.class
)
public class Address {
  @BoundFlag(
      formalName = "Address Type",
      description = "Indicates the type of address.",
      useName = "type",
      typeAdapter = TokenAdapter.class
  )
  @ValueConstraints(
      allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, allowOthers = true, values = {@AllowedValue(value = "home", description = "A home address."), @AllowedValue(value = "work", description = "A work address.")})
  )
  private String _type;

  @BoundField(
      formalName = "Address line",
      description = "A single line of an address.",
      useName = "addr-line",
      maxOccurs = -1
  )
  @GroupAs(
      name = "addr-lines",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<String> _addrLines;

  /**
   * "City, town or geographical region for the mailing address."
   */
  @BoundField(
      formalName = "City",
      description = "City, town or geographical region for the mailing address.",
      useName = "city"
  )
  private String _city;

  /**
   * "State, province or analogous geographical region for a mailing address."
   */
  @BoundField(
      formalName = "State",
      description = "State, province or analogous geographical region for a mailing address.",
      useName = "state"
  )
  private String _state;

  /**
   * "Postal or ZIP code for mailing address."
   */
  @BoundField(
      formalName = "Postal Code",
      description = "Postal or ZIP code for mailing address.",
      useName = "postal-code"
  )
  private String _postalCode;

  /**
   * "The ISO 3166-1 alpha-2 country code for the mailing address."
   */
  @BoundField(
      formalName = "Country Code",
      description = "The ISO 3166-1 alpha-2 country code for the mailing address.",
      useName = "country"
  )
  @ValueConstraints(
      matches = @Matches(level = IConstraint.Level.ERROR, pattern = "[A-Z]{2}")
  )
  private String _country;

  public Address() {
  }

  public String getType() {
    return _type;
  }

  public void setType(String value) {
    _type = value;
  }

  public List<String> getAddrLines() {
    return _addrLines;
  }

  public void setAddrLines(List<String> value) {
    _addrLines = value;
  }

  /**
   * Add a new {@link String} item to the underlying collection.
   * @param item the item to add
   * @return {@code true}
   */
  public boolean addAddrLine(String item) {
    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
    if (_addrLines == null) {
      _addrLines = new LinkedList<>();
    }
    return _addrLines.add(value);
  }

  /**
   * Remove the first matching {@link String} item from the underlying collection.
   * @param item the item to remove
   * @return {@code true} if the item was removed or {@code false} otherwise
   */
  public boolean removeAddrLine(String item) {
    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
    return _addrLines == null ? false : _addrLines.remove(value);
  }

  public String getCity() {
    return _city;
  }

  public void setCity(String value) {
    _city = value;
  }

  public String getState() {
    return _state;
  }

  public void setState(String value) {
    _state = value;
  }

  public String getPostalCode() {
    return _postalCode;
  }

  public void setPostalCode(String value) {
    _postalCode = value;
  }

  public String getCountry() {
    return _country;
  }

  public void setCountry(String value) {
    _country = value;
  }

  @Override
  public String toString() {
    return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
  }
}