Find the valid option for the selected data, allowing for option/code and legacy matching.

@param options the list of options
@param selected the option to search for
@param handleInvalid true if allow handle invalid option
@return the valid option
766383
private Object findValidOption(final List<?> options, final Object selected,
			final boolean handleInvalid) {

		// No selection made
		if (selected == null) {
			// No Selection required, or no options to select
			if (isAllowNoSelection() || options == null || options.isEmpty()) {
				return null;
			} else { // Selection is required
				// Check if NULL is an option
				if (SelectListUtil.containsOption(options, null)) {
					return null;
				}

				// Must have a selected option
				throw new IllegalStateException(
						"A valid option must be selected for lists that require a selected option.");
			}
		}

		// Check we have a valid option and if we find it via Option/Code or Legacy matching, return the matching option
		if (options != null) {
			Object option = SelectListUtil.getOptionWithMatching(options, selected);
			if (option != null) {
				return option;
			}
		}

		// Editable with User Entered Text
		if (isEditable() && selected instanceof String) {
			return selected;
		}

		// Handle invalid option
		if (handleInvalid) {
			Object valid = doHandleInvalidOption(selected);
			setSelected(valid);
			return valid;
		} else {
			throw new IllegalStateException(
					"The selected option \"" + selected + "\" is not an available option.");
		}

	}
1264073
public ElementActionBuilder select(String option) {
        DropDownSelectAction action = new DropDownSelectAction();
        action.setOption(option);
        action(action);
        return new ElementActionBuilder(action);
    }
604048
public void select(String optionLocator) {
        getDispatcher().beforeSelect(this, optionLocator);
        
        if (StringUtils.isBlank(optionLocator)) {
            throw new IllegalArgumentException("Locator cannot be null or empty.");
        }
        if (optionLocator.split("=").length != 2) {
            StringBuilder errMsg = new StringBuilder("Invalid locator specified :");
            errMsg.append(optionLocator);
            errMsg.append(". Locator should be of the form label=<value> (or) ");
            errMsg.append("value=<value> (or) ");
            errMsg.append("index=<value> (or) ");
            errMsg.append("id=<value>.");
            throw new IllegalArgumentException(errMsg.toString());
        }
        String locatorToUse = optionLocator.split("=")[1].trim();
        String tLocator = optionLocator.toLowerCase().split("=")[0].trim();
        if (tLocator.indexOf("label") >= 0) {
            // label was given
            new Select(getElement()).selectByVisibleText(locatorToUse);
        } else if (tLocator.indexOf("value") >= 0) {
            // value was given
            new Select(getElement()).selectByValue(locatorToUse);
        } else if (tLocator.indexOf("index") >= 0) {
            // index was given
            new Select(getElement()).selectByIndex(Integer.parseInt(locatorToUse));
        } else if (tLocator.indexOf("id") >= 0) {
            // id was given
            getElement().findElementById(locatorToUse).click();
        } else {
            throw new NoSuchElementException("Unable to find " + optionLocator);
        }
        
        getDispatcher().afterSelect(this, optionLocator);
    }
399996
@Override
    public String getSelectedOption() throws WidgetException {
        try {
            Select select = new Select(getByLocator());
            List<String> selectedOptions = select.getSelectedOptions();
            if (selectedOptions != null && selectedOptions.size() > 0) {
                return selectedOptions.get(0);
            } else {
                return "";
            }
        } catch (Exception e) {
            throw new WidgetException("Error while fetching selected options", getByLocator(), e);
        }
    }
981239
@When("^I select '(.+?)' on the element on index '(\\d+?)'$")
    public void elementSelect(String option, Integer index) {
        Select sel = null;
        sel = new Select(commonspec.getPreviousWebElements().getPreviousWebElements().get(index));

        sel.selectByVisibleText(option);
    }
135427
protected void validateOrderList(SqlSelect select) {
		// ORDER BY is validated in a scope where aliases in the SELECT clause
		// are visible. For example, "SELECT empno AS x FROM emp ORDER BY x"
		// is valid.
		SqlNodeList orderList = select.getOrderList();
		if (orderList == null) {
			return;
		}
		if (!shouldAllowIntermediateOrderBy()) {
			if (!cursorSet.contains(select)) {
				throw newValidationError(select, RESOURCE.invalidOrderByPos());
			}
		}
		final SqlValidatorScope orderScope = getOrderScope(select);
		Objects.requireNonNull(orderScope);

		List<SqlNode> expandList = new ArrayList<>();
		for (SqlNode orderItem : orderList) {
			SqlNode expandedOrderItem = expand(orderItem, orderScope);
			expandList.add(expandedOrderItem);
		}

		SqlNodeList expandedOrderList = new SqlNodeList(
			expandList,
			orderList.getParserPosition());
		select.setOrderBy(expandedOrderList);

		for (SqlNode orderItem : expandedOrderList) {
			validateOrderItem(select, orderItem);
		}
	}
207254
function validOptions(options) {
  const _validOptions = validOptionNames.concat(legacyOptionNames);

  for (const name in options) {
    if (ignoreOptionNames.indexOf(name) !== -1) {
      continue;
    }

    if (_validOptions.indexOf(name) === -1 && options.validateOptions) {
      return new MongoError(`option ${name} is not supported`);
    } else if (_validOptions.indexOf(name) === -1) {
      console.warn(`the options [${name}] is not supported`);
    }

    if (legacyOptionNames.indexOf(name) !== -1) {
      console.warn(
        `the server/replset/mongos/db options are deprecated, ` +
          `all their options are supported at the top level of the options object [${validOptionNames}]`
      );
    }
  }
}
526491
@SuppressWarnings("unchecked")
    public List<String> getOptionValues(final String optionName) {
        if (optionName.length() == 1) {
            return getOptionValues(optionName.charAt(0));
        }

        return commandLine.getValues("--" + optionName);
    }
1297422
private function isValidSelectionMethod($selectionMethod)
    {
        return in_array($selectionMethod, [
            self::SELECTION_BROWSE,
            self::SELECTION_DROPDOWN,
            self::SELECTION_LIST_WITH_RADIO_BUTTONS,
            self::SELECTION_LIST_WITH_CHECKBOXES,
            self::SELECTION_MULTIPLE_SELECTION_LIST,
            self::SELECTION_TEMPLATE_BASED_MULTIPLE,
            self::SELECTION_TEMPLATE_BASED_SINGLE,
        ], true);
    }
1069155
function checkOptions(options) {
                // @TODO: should we throw an error if there are incorrect options provided?
                options = _.pick(options, permittedOptions);

                let validationErrors = utils.validateOptions(options);

                if (_.isEmpty(validationErrors)) {
                    return Promise.resolve(options);
                }

                // For now, we can only handle showing the first validation error
                return Promise.reject(validationErrors[0]);
            }
1310009
function validateRuleOptions(id, options, source) {
		var validateRule = validators.rules[id],
			message,
			severity,
			localOptions,
			schema = getRuleOptionsSchema(id),
			validSeverity = true;

		/* ORION no CQ for is-my-json-valid library
		 if (!validateRule && schema) {
			validateRule = schemaValidator(schema, {
				verbose: true
			});
			validators.rules[id] = validateRule;
		}*/

		// if it's not an array, it should be just a severity
		if (Array.isArray(options)) {
			localOptions = options.concat(); // clone
			severity = localOptions.shift();
		} else {
			severity = options;
			localOptions = [];
		}

		validSeverity = (
			severity === 0 || severity === 1 || severity === 2 ||
			(typeof severity === "string" && /^(?:off|warn|error)$/i.test(severity))
		);

		if (validateRule) {
			validateRule(localOptions);
		}

		if ((validateRule && validateRule.errors) || !validSeverity) {
			message = [
				source, ":\n",
				"\tConfiguration for rule \"", id, "\" is invalid:\n"
			];

			if (!validSeverity) {
				message.push(
					"\tSeverity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '",
					util.inspect(severity).replace(/'/g, "\"").replace(/\n/g, ""),
					"').\n"
				);
			}

			if (validateRule && validateRule.errors) {
				validateRule.errors.forEach(function(error) {
					message.push(
						"\tValue \"", error.value, "\" ", error.message, ".\n"
					);
				});
			}

			throw new Error(message.join(""));
		}
	}
77977
public static cacheselector[] get(nitro_service service, options option) throws Exception{
		cacheselector obj = new cacheselector();
		cacheselector[] response = (cacheselector[])obj.get_resources(service,option);
		return response;
	}
846696
public static String selectOne(final String title, final String[] optionNames, final String[] optionValues, final int defaultOption) {
        if (optionNames.length != optionValues.length) {
            throw new IllegalArgumentException("option names and values must have same length");
        }

        ConsoleMenu.println("Please chose " + title + DEFAULT_TITLE + defaultOption + ")");

        for (int i = 0; i < optionNames.length; i++) {
            ConsoleMenu.println(i + 1 + ") " + optionNames[i]);
        }

        int choice;

        do {
            choice = ConsoleMenu.getInt("Your Choice 1-" + optionNames.length + ": ", defaultOption);
        } while (choice <= 0 || choice > optionNames.length);

        return optionValues[choice - 1];
    }
471588
function (suggestion, selectionOptions) {
        var that = this,
            formatSelected = that.options.formatSelected || that.type.formatSelected,
            hasSameValues = selectionOptions && selectionOptions.hasSameValues,
            hasBeenEnriched = selectionOptions && selectionOptions.hasBeenEnriched,
            formattedValue,
            typeFormattedValue = null;


        if ($.isFunction(formatSelected)) {
            formattedValue = formatSelected.call(that, suggestion);
        }

        if (typeof formattedValue !== 'string') {
            formattedValue = suggestion.value;

            if (that.type.getSuggestionValue) {
                typeFormattedValue = that.type.getSuggestionValue(that, {
                    suggestion: suggestion,
                    hasSameValues: hasSameValues,
                    hasBeenEnriched: hasBeenEnriched,
                });

                if (typeFormattedValue !== null) {
                    formattedValue = typeFormattedValue;
                }
            }
        }

        return formattedValue;
    }
1261681
public static function invoke(
        bool $valid,
        array $options = [],
        string $defaultInvalidCode = self::DEFAULT_INVALID_CODE,
        string $validCode = self::DEFAULT_VALID_CODE
    ): string {
        if ($valid) {
            return $validCode;
        };

        return Property::getString(
            $options,
            static::OPTION_INVALID_CODE,
            $defaultInvalidCode
        );
    }
849618
public static <T> DropDownChoice<T> newDropDownChoice(final String id, final IModel<T> model,
		final List<? extends T> choices)
	{
		final DropDownChoice<T> dropDownChoice = new DropDownChoice<>(id, model, choices);
		dropDownChoice.setOutputMarkupId(true);
		return dropDownChoice;
	}
683695
function validateOptions(operation, type, useCoerce) {
  var options = { useCoerce: useCoerce };

  // capitalize type
  var suffix = type[0].toUpperCase() + type.slice(1);

  // Get remove option (ex: options.removeHeader)
  var removeAdditional = lookup(operation, 'options', 'remove' + suffix);

  if (typeof removeAdditional === 'undefined') {
    removeAdditional = true;
  }
  options.removeAdditional = !!removeAdditional;

  return options;
}