001// Generated from: ../../../../../../../../oscal/src/metaschema/oscal_control-common_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.TokenAdapter; 006import dev.metaschema.core.datatype.markup.MarkupLine; 007import dev.metaschema.core.datatype.markup.MarkupLineAdapter; 008import dev.metaschema.core.model.IBoundObject; 009import dev.metaschema.core.model.IMetaschemaData; 010import dev.metaschema.core.model.JsonGroupAsBehavior; 011import dev.metaschema.core.model.constraint.IConstraint; 012import dev.metaschema.core.util.ObjectUtils; 013import dev.metaschema.databind.model.annotations.AllowedValue; 014import dev.metaschema.databind.model.annotations.AllowedValues; 015import dev.metaschema.databind.model.annotations.BoundField; 016import dev.metaschema.databind.model.annotations.BoundFlag; 017import dev.metaschema.databind.model.annotations.GroupAs; 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 * Presenting a choice among alternatives. 029 */ 030@MetaschemaAssembly( 031 formalName = "Selection", 032 description = "Presenting a choice among alternatives.", 033 name = "parameter-selection", 034 moduleClass = OscalControlCommonModule.class, 035 remarks = "A set of parameter value choices, that may be picked from to set the parameter value." 036) 037public class ParameterSelection implements IBoundObject { 038 private final IMetaschemaData __metaschemaData; 039 040 /** 041 * Describes the number of selections that must occur. Without this setting, only one value should be assumed to be permitted. 042 */ 043 @BoundFlag( 044 formalName = "Parameter Cardinality", 045 description = "Describes the number of selections that must occur. Without this setting, only one value should be assumed to be permitted.", 046 name = "how-many", 047 typeAdapter = TokenAdapter.class, 048 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(id = "oscal-parameter-how-many-type", 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.")})) 049 ) 050 private String _howMany; 051 052 /** 053 * A value selection among several such options. 054 */ 055 @BoundField( 056 formalName = "Choice", 057 description = "A value selection among several such options.", 058 useName = "choice", 059 maxOccurs = -1, 060 groupAs = @GroupAs(name = "choice", inJson = JsonGroupAsBehavior.LIST), 061 typeAdapter = MarkupLineAdapter.class 062 ) 063 private List<MarkupLine> _choice; 064 065 /** 066 * Constructs a new {@code dev.metaschema.oscal.lib.model.ParameterSelection} instance with no metadata. 067 */ 068 public ParameterSelection() { 069 this(null); 070 } 071 072 /** 073 * Constructs a new {@code dev.metaschema.oscal.lib.model.ParameterSelection} instance with the specified metadata. 074 * 075 * @param data 076 * the metaschema data, or {@code null} if none 077 */ 078 public ParameterSelection(IMetaschemaData data) { 079 this.__metaschemaData = data; 080 } 081 082 @Override 083 public IMetaschemaData getMetaschemaData() { 084 return __metaschemaData; 085 } 086 087 /** 088 * Get the "{@literal Parameter Cardinality}". 089 * 090 * <p> 091 * Describes the number of selections that must occur. Without this setting, only one value should be assumed to be permitted. 092 * 093 * @return the how-many value, or {@code null} if not set 094 */ 095 @Nullable 096 public String getHowMany() { 097 return _howMany; 098 } 099 100 /** 101 * Set the "{@literal Parameter Cardinality}". 102 * 103 * <p> 104 * Describes the number of selections that must occur. Without this setting, only one value should be assumed to be permitted. 105 * 106 * @param value 107 * the how-many value to set, or {@code null} to clear 108 */ 109 public void setHowMany(@Nullable String value) { 110 _howMany = value; 111 } 112 113 /** 114 * Get the "{@literal Choice}". 115 * 116 * <p> 117 * A value selection among several such options. 118 * 119 * @return the choice value 120 */ 121 @NonNull 122 public List<MarkupLine> getChoice() { 123 if (_choice == null) { 124 _choice = new LinkedList<>(); 125 } 126 return ObjectUtils.notNull(_choice); 127 } 128 129 /** 130 * Set the "{@literal Choice}". 131 * 132 * <p> 133 * A value selection among several such options. 134 * 135 * @param value 136 * the choice value to set 137 */ 138 public void setChoice(@NonNull List<MarkupLine> value) { 139 _choice = value; 140 } 141 142 /** 143 * Add a new {@link MarkupLine} item to the underlying collection. 144 * @param item the item to add 145 * @return {@code true} 146 */ 147 public boolean addChoice(MarkupLine item) { 148 MarkupLine value = ObjectUtils.requireNonNull(item,"item cannot be null"); 149 if (_choice == null) { 150 _choice = new LinkedList<>(); 151 } 152 return _choice.add(value); 153 } 154 155 /** 156 * Remove the first matching {@link MarkupLine} item from the underlying collection. 157 * @param item the item to remove 158 * @return {@code true} if the item was removed or {@code false} otherwise 159 */ 160 public boolean removeChoice(MarkupLine item) { 161 MarkupLine value = ObjectUtils.requireNonNull(item,"item cannot be null"); 162 return _choice != null && _choice.remove(value); 163 } 164 165 @Override 166 public String toString() { 167 return ObjectUtils.notNull(new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString()); 168 } 169}