示例#1
0
  /** Разбор аргументов */
  @Override
  public int parseArguments(Parameters params) throws CmdLineException {
    String token = params.getParameter(0);
    int usedParams = 1;

    OptionSize size = new OptionSize();

    // отцепляем цифры
    int i = 0;
    for (; i < token.length(); ++i) if (!Character.isDigit(token.charAt(i))) break;

    // нету чисел
    if (i - 1 < 1) throw new CmdLineException(owner, "Illegal argument in -size option.");

    // парсим первое число
    size.width = Integer.parseInt(token.substring(0, i));

    // просканили весь параметр
    if (i == token.length()) {
      if (params.size() < 2)
        throw new CmdLineException(owner, "Wrong number arguments in -size option.");
      token = params.getParameter(1);
      usedParams++;
      i = 0;
    }

    if (token.charAt(i) != 'x')
      throw new CmdLineException(owner, "Illegal argument in -size option.");

    i++;

    // просканили весь параметр
    if (i == token.length()) {
      if (params.size() < usedParams + 1)
        throw new CmdLineException(owner, "Wrong number arguments in -size option.");
      token = params.getParameter(usedParams);
      usedParams++;
      i = 0;
    }

    // отцепляем цифры второго числа
    int j = i;
    for (; i < token.length(); ++i) if (!Character.isDigit(token.charAt(i))) break;

    // за цифрами что-то есть
    if (i != token.length()) throw new CmdLineException(owner, "Illegal argument in -size option.");

    size.height = Integer.parseInt(token.substring(j, i));

    setter.addValue(size);

    return usedParams;
  }
    @Override
    public int parseArguments(Parameters params) throws CmdLineException {

      boolean value;
      boolean hasParam;
      try {
        String nextArg = params.getParameter(0);
        if (nextArg.equals("true") || nextArg.equals("1")) {
          value = true;
          hasParam = true;
        } else if (nextArg.equals("false") || nextArg.equals("0")) {
          value = false;
          hasParam = true;
        } else {
          // Next arg is not a param for this flag. No param means set flag to true.
          value = true;
          hasParam = false;
        }
      } catch (CmdLineException e) {
        // No additional args on command line. No param means set flag to true.
        value = true;
        hasParam = false;
      }

      setter.addValue(value);
      return hasParam ? 1 : 0;
    }
      @Override
      public int parseArguments(Parameters params) throws CmdLineException {
        String param = null;
        try {
          param = params.getParameter(0);
        } catch (CmdLineException e) {
          param = null; // to stop linter complaints
        }

        if (param == null) {
          setter.addValue(true);
          return 0;
        } else {
          String lowerParam = param.toLowerCase();
          if (TRUES.contains(lowerParam)) {
            setter.addValue(true);
          } else if (FALSES.contains(lowerParam)) {
            setter.addValue(false);
          } else {
            setter.addValue(true);
            return 0;
          }
          return 1;
        }
      }
 @Override
 public int parseArguments(Parameters params) throws CmdLineException {
   String parameter = params.getParameter(0);
   // An empty string should be an empty list, not a list containing the empty item
   if (!parameter.isEmpty()) {
     for (String item : parameter.split(",")) {
       setter.addValue(parseItem(item));
     }
   }
   return 1;
 }
示例#5
0
 @Override
 public int parseArguments(Parameters params) throws CmdLineException {
   String arg = params.getParameter(0);
   try {
     Charset charset = Charset.forName(arg);
     setter.addValue(charset);
   } catch (IllegalCharsetNameException e) {
     throw new CmdLineException(owner, e);
   }
   return 1;
 }
  /** Tries to parse {@code HyperPoint[]} argument from {@link Parameters}. */
  @SuppressWarnings("deprecation") // we don't have proper locale support in Hyst
  @Override
  public int parseArguments(Parameters params) throws CmdLineException {
    int counter = 0;
    int numDims = -1;

    for (; counter < params.size(); counter++) {
      String param = params.getParameter(counter);

      if (param.startsWith("-")) break;

      for (String partStr : param.split(" ")) {
        if (!partStr.startsWith("(") || !partStr.endsWith(")")) {
          // deprecated: we don't have proper locale support in Hyst
          throw new CmdLineException(
              owner, "Argument should start and end with parenthesis: '" + partStr + "'");
        }

        // trim parenthesis
        partStr = partStr.substring(1, partStr.length() - 1);

        String[] dims = partStr.split(";");

        if (numDims == -1) numDims = dims.length;
        else if (numDims != dims.length) {
          // deprecated: we don't have proper locale support in Hyst
          throw new CmdLineException(
              owner,
              "Argument has wrong number of dimensions (expected "
                  + numDims
                  + "): '"
                  + partStr
                  + "'");
        }

        HyperRectangle hr = new HyperRectangle(dims.length);

        for (int i = 0; i < dims.length; ++i) {
          try {
            String[] minmax = dims[i].split(",");

            if (minmax.length != 2) {
              // deprecated: we don't have proper locale support in Hyst
              throw new CmdLineException(
                  owner,
                  "Dimension in HyperRectangle expected two parts: '"
                      + dims[i]
                      + "' in '"
                      + partStr
                      + "'");
            }

            double min = Double.parseDouble(minmax[0]);
            double max = Double.parseDouble(minmax[1]);

            if (max < min) {
              // deprecated: we don't have proper locale support in Hyst
              throw new CmdLineException(
                  owner,
                  "min > max in dimension in HyperRectangle: '"
                      + dims[i]
                      + "' in '"
                      + partStr
                      + "'");
            }

            hr.dims[i] = new Interval(min, max);
          } catch (NumberFormatException e) {
            // deprecated: we don't have proper locale support in Hyst
            throw new CmdLineException(
                owner, "Error parsing argument as number: '" + dims[i] + "'");
          }
        }

        setter.addValue(hr);
      }
    }

    return counter;
  }