ParameterSelection.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.BoundFieldValue;
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.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.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupLineAdapter;
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;

/**
 * Presenting a choice among alternatives.
 */
@MetaschemaAssembly(
    formalName = "Selection",
    description = "Presenting a choice among alternatives.",
    name = "parameter-selection",
    metaschema = OscalControlCommonMetaschema.class,
    remarks = "A set of parameter value choices, that may be picked from to set the parameter value."
)
public class ParameterSelection {
  @BoundFlag(
      formalName = "Parameter Cardinality",
      description = "Describes the number of selections that must occur. Without this setting, only one value should be assumed to be permitted.",
      useName = "how-many",
      typeAdapter = TokenAdapter.class
  )
  @ValueConstraints(
      allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "one", description = "Only one value is permitted."), @AllowedValue(value = "one-or-more", description = "One or more values are permitted.")})
  )
  private String _howMany;

  /**
   * "A value selection among several such options."
   */
  @BoundField(
      formalName = "Choice",
      description = "A value selection among several such options.",
      useName = "choice",
      maxOccurs = -1
  )
  @BoundFieldValue(
      typeAdapter = MarkupLineAdapter.class
  )
  @GroupAs(
      name = "choice",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<MarkupLine> _choice;

  public ParameterSelection() {
  }

  public String getHowMany() {
    return _howMany;
  }

  public void setHowMany(String value) {
    _howMany = value;
  }

  public List<MarkupLine> getChoice() {
    return _choice;
  }

  public void setChoice(List<MarkupLine> value) {
    _choice = value;
  }

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

  /**
   * Remove the first matching {@link MarkupLine} 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 removeChoice(MarkupLine item) {
    MarkupLine value = ObjectUtils.requireNonNull(item,"item cannot be null");
    return _choice == null ? false : _choice.remove(value);
  }

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