Package com.beust.jcommander

Examples of com.beust.jcommander.ParameterException


  public Float convert(String value) {
    try {
      return Float.parseFloat(value);
    } catch(NumberFormatException ex) {
      throw new ParameterException(getErrorString(value, "a float"));
    }
  }
View Full Code Here


  public Double convert(String value) {
    try {
      return Double.parseDouble(value);
    } catch(NumberFormatException ex) {
      throw new ParameterException(getErrorString(value, "a double"));
    }
  }
View Full Code Here

  public static class NamedLikeRFile implements IParameterValidator {
    @Override
    public void validate(String name, String value) throws ParameterException {
      if (!value.endsWith(".rf")) {
        throw new ParameterException("File must end with .rf and '" + value + "' does not.");
      }
    }
View Full Code Here

  public static class IsSupportedCompressionAlgorithm implements IParameterValidator {
    @Override
    public void validate(String name, String value) throws ParameterException {
      String[] algorithms = Compression.getSupportedAlgorithms();
      if (!((Arrays.asList(algorithms)).contains(value))) {
        throw new ParameterException("Compression codec must be one of " + Arrays.toString(algorithms));
      }
    }
View Full Code Here

    public AuthenticationToken convert(String value) {
      try {
        return Class.forName(value).asSubclass(AuthenticationToken.class).newInstance();
      } catch (Exception e) {
        // Catching ClassNotFoundException, ClassCastException, InstantiationException and IllegalAccessException
        throw new ParameterException(e);
      }
    }
View Full Code Here

    @Override
    public Class convert(String value) {

        if (isBlank(value)) {
            throw new ParameterException(getErrorString("a blank value", "a class"));
        }

        try {
            return Class.forName(value);
        } catch (ClassNotFoundException e) {
            throw new ParameterException(getErrorString(value, "a class"));
        }
    }
View Full Code Here

    @Override
    public void validate(String name, String value) throws ParameterException {
      try {
        int batch = Integer.parseInt(value);
        if (batch < 0) {
          throw new ParameterException("Parameter " + name + " should be non-negative number.");
        }
      } catch (NumberFormatException e) {
        throw new ParameterException("Parameter " + name + " should be non-negative number.");
      }

    }
View Full Code Here

    try {
      boolean hasToken = (token != null);
      boolean hasTokenOptions = !loginOptions.isEmpty();

      if (hasToken && password != null) {
        throw new ParameterException("Can not supply '--pass' option with '--tokenClass' option");
      }

      Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
          reader.getTerminal().setEchoEnabled(true);
        }
      });

      // Need either both a token and options, or neither, but not just one.
      if (hasToken != hasTokenOptions) {
        throw new ParameterException("Must supply either both or neither of '--tokenClass' and '--tokenProperty'");
      } else if (hasToken) { // implied hasTokenOptions
        // Fully qualified name so we don't shadow java.util.Properties
        org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties props;
        // and line wrap it because the package name is so long
        props = new org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties();

        props.putAllStrings(loginOptions);
        token.init(props);
      } else {
        // Read password if the user explicitly asked for it, or didn't specify anything at all
        if ("stdin".equals(password) || password == null) {
          password = reader.readLine("Password: ", '*');
        }

        if (password == null) {
          // User cancel, e.g. Ctrl-D pressed
          throw new ParameterException("No password or token option supplied");
        } else {
          this.token = new PasswordToken(password);
        }
      }

View Full Code Here

  @Override
  public Boolean convert(String value) {
    if ("false".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value)) {
      return Boolean.parseBoolean(value);
    } else {
      throw new ParameterException(getErrorString(value, "a boolean"));
    }
  }
View Full Code Here

  @Override
  public Integer convert(String value) {
    try {
      return Integer.parseInt(value);
    } catch(NumberFormatException ex) {
      throw new ParameterException(getErrorString(value, "an integer"));
    }
  }
View Full Code Here

TOP

Related Classes of com.beust.jcommander.ParameterException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.