Beispiel #1
0
  /**
   * Set the value of a particular option in the stash.
   *
   * @param optionName The name of the option to set.
   * @param optionValue The value of the option to set.
   */
  public static void set(String optionName, String optionValue) {
    // Ensure that the options stash is created
    init();

    // Make sure that the option being set is an allowed one
    if (isLegal(optionName)) {
      Option<?> optionToSet = get(optionName);
      List<String> vals = null;

      if (isEnum(optionName)) {
        // The string is a list of comma separated values
        String[] rawValues = optionValue.split(String.valueOf(COMMA));
        vals = new ArrayList<String>(rawValues.length);
        for (String rawV : rawValues) {
          String rawValue;
          if (optionToSet.isCaseSensitive()) {
            rawValue = rawV;
          } else {
            rawValue = rawV.toLowerCase();
          }
          Map<String, String> enumValueMap;
          enumValueMap = Enum.class.cast(optionToSet).getEnumValues();
          if (enumValueMap.containsKey(rawValue)) {
            vals.add(rawValue);
          }
        }
      } else if (isSwitch(optionName)) {
        vals = new ArrayList<String>(1);
        vals.add(String.valueOf(Boolean.valueOf(optionValue)));
      } else if (isArgument(optionName)) {
        vals = new ArrayList<String>(1);
        if (optionToSet.isCaseSensitive()) {
          vals.add(optionValue);
        } else {
          vals.add(optionValue.toLowerCase());
        }
      }

      if (vals != null) {
        optionToSet.setValue(vals);
      }

      options.put(optionName, optionToSet);

      // Handle the special case of debug
      Boolean debugValue = getBoolean("debug"); // NON-NLS
      if (debugValue != null) {
        debug = debugValue;
      }
    }
  }