當前位置: 首頁>>代碼示例>>Java>>正文


Java ParameterException類代碼示例

本文整理匯總了Java中com.beust.jcommander.ParameterException的典型用法代碼示例。如果您正苦於以下問題:Java ParameterException類的具體用法?Java ParameterException怎麽用?Java ParameterException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ParameterException類屬於com.beust.jcommander包,在下文中一共展示了ParameterException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parse

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
/**
 * Parses command line arguments and populates this command line instance.
 * <p>
 * If the command line arguments include the "help" argument, or if the
 * arguments have incorrect values or order, then usage information is
 * printed to {@link System#out} and the program terminates.
 *
 * @param args
 *            the command line arguments
 * @return an instance of the parsed arguments object
 */
public Arguments parse(String[] args) {

    JCommander jCommander = new JCommander(this);
    jCommander.setProgramName("jsonschema2pojo");

    try {
        jCommander.parse(args);

        if (this.showHelp) {
            jCommander.usage();
            exit(EXIT_OKAY);
        }
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        jCommander.usage();
        exit(EXIT_ERROR);
    }

    return this;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:Arguments.java

示例2: validate

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
@Override
@SuppressWarnings("ResultOfMethodCallIgnored")
public void validate(String name, String value) throws ParameterException {

    boolean invalid = false;
    File file = new File(value);

    if (file.exists()) {
        invalid = !file.canWrite() || !file.isFile();
    } else {
        try {
            file.createNewFile();
            file.delete();
        } catch (IOException error) {
            invalid = true;
        }
    }

    if (invalid) {
        String message = String.format("expecting a writable file: %s %s", name, value);
        throw new ParameterException(message);
    }

}
 
開發者ID:vy,項目名稱:hrrs,代碼行數:25,代碼來源:WritableFileValidator.java

示例3: readPassword

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
public char[] readPassword(boolean echoInput) {
  try {
    writer.flush();
    Method method;
    if (echoInput) {
        method = console.getClass().getDeclaredMethod("readLine");
        return ((String) method.invoke(console)).toCharArray();
    } else {
        method = console.getClass().getDeclaredMethod("readPassword");
        return (char[]) method.invoke(console);
    }
  }
  catch (Exception e) {
    throw new ParameterException(e);
  }
}
 
開發者ID:georghinkel,項目名稱:ttc2017smartGrids,代碼行數:17,代碼來源:JDK6Console.java

示例4: main

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
public static void main(String[] args) {

		App app = new App();
		JCommander jc = new JCommander(app);

		try {
			jc.parse(args);
		} catch (ParameterException pe) {
			System.err.println(pe.getMessage());
			jc.usage();
			return;
		}

		app.build();

	}
 
開發者ID:georghinkel,項目名稱:ttc2017smartGrids,代碼行數:17,代碼來源:App.java

示例5: VerbSenseArgumentCounter

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
private VerbSenseArgumentCounter(String... args) {
    JCommander cmd = new JCommander(this);
    cmd.setProgramName(this.getClass().getSimpleName());
    try {
        if (args.length == 0) {
            cmd.usage();
            System.exit(0);
        }
        cmd.parse(args);
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        cmd.usage();
        System.exit(1);
    }
    initializeDb();
    initializeAnnotator();
    validateDir();
}
 
開發者ID:clearwsd,項目名稱:clearwsd,代碼行數:19,代碼來源:VerbSenseArgumentCounter.java

示例6: WordSenseCLI

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
WordSenseCLI(String[] args) {
    cmd = new JCommander(this);
    cmd.setProgramName(WordSenseCLI.class.getSimpleName());
    try {
        cmd.parse(args);
        if (help || args.length == 0) {
            System.out.println(helpMessage);
            cmd.usage();
            System.exit(0);
        }
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        cmd.usage();
        System.exit(1);
    }
}
 
開發者ID:clearwsd,項目名稱:clearwsd,代碼行數:17,代碼來源:WordSenseCLI.java

示例7: validate

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
@Override
public void validate(String name, String value) throws ParameterException {
  String[] elements = value.split(",");
  boolean sawRowId = false;
  for (String element : elements) {
    if (DelimitedIngest.ROW_ID.equals(element)) {
      if (sawRowId) {
        throw new ParameterException("Saw multiple instance of '" + DelimitedIngest.ROW_ID + "' in the column mapping.");
      }
      sawRowId = true;
    }
  }
  if (!sawRowId) {
    throw new ParameterException("One element in the column mapping must be '" + DelimitedIngest.ROW_ID + "', but found none");
  }
}
 
開發者ID:joshelser,項目名稱:accumulo-delimited-ingest,代碼行數:17,代碼來源:DelimitedIngestArguments.java

示例8: main

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
  initializeCommands();
  Runner runner = new Runner();
  Server server = new Server();

  JCommander.Builder builder = JCommander.newBuilder().addObject(runner);
  commands.forEach(command -> builder
      .addCommand(command.getClass().getSimpleName().toLowerCase(), command));
  JCommander jc = builder.build();
  try {
    jc.parse(args);
    Optional<SubCommandBase> selectedCommand = commands.stream().filter(
        command -> command.getClass().getSimpleName().toLowerCase()
            .equals(jc.getParsedCommand())).findFirst();
    if (selectedCommand.isPresent()) {
      selectedCommand.get().run();
    } else {
      jc.usage();
    }
  } catch (ParameterException exception) {
    System.err.println("Wrong parameters: " + exception.getMessage());
    jc.usage();
  }

}
 
開發者ID:apache,項目名稱:incubator-ratis,代碼行數:26,代碼來源:Runner.java

示例9: validate

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
@Override
public void validate(String name, String value) throws ParameterException {
    File file = new File(value);
    ParameterException exception = new ParameterException("File " + file.getAbsolutePath() + " does not exist and cannot be created.");
    try {

        if (!file.exists()) {
            boolean canCreate = file.createNewFile();
            if (canCreate) {
                FileDeleteStrategy.FORCE.delete(file);
            } else {
                throw exception;
            }

        }
    } catch (IOException exc) {
        throw exception;
    }

}
 
開發者ID:chenshuiluke,項目名稱:jresume,代碼行數:21,代碼來源:FileLocationValidator.java

示例10: convert

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
@Override
public Level convert(String value) {
  Level convertedValue = Level.valueOf(value);

  if (convertedValue == null) {
    throw new ParameterException("Value " + value + "can not be converted to a logging level.");
  }
  return convertedValue;
}
 
開發者ID:datastax,項目名稱:simulacron,代碼行數:10,代碼來源:CommandLineArguments.java

示例11: convert

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
@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"));
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:ClassConverter.java

示例12: convert

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
public URL convert(String value) {
    if (isBlank(value)) {
        throw new ParameterException(getErrorString("a blank value", "a valid URL"));
    }

    try {
        return URLUtil.parseURL(value);
    } catch (IllegalArgumentException e) {
        throw new ParameterException(getErrorString(value, "a valid URL"));
    }

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:UrlConverter.java

示例13: validate

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
@Override
public void validate(String name, String loggerLevelSpecs) throws ParameterException {
    if (!loggerLevelSpecs.matches(LOGGER_LEVEL_SPECS_REGEX)) {
        String message = String.format("invalid logger level specification: %s %s", name, loggerLevelSpecs);
        throw new ParameterException(message);
    }
}
 
開發者ID:vy,項目名稱:hrrs,代碼行數:8,代碼來源:LoggerLevelSpecsValidator.java

示例14: init

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
private void init(String fileName) {
  try {
    properties = new Properties();
    URL url = ClassLoader.getSystemResource(fileName);
    if (url != null) {
      properties.load(url.openStream());
    } else {
      throw new ParameterException("Could not find property file: " + fileName
          + " on the class path");
    }
  }
  catch (IOException e) {
    throw new ParameterException("Could not open property file: " + fileName);
  }
}
 
開發者ID:georghinkel,項目名稱:ttc2017smartGrids,代碼行數:16,代碼來源:PropertyFileDefaultProvider.java

示例15: validate

import com.beust.jcommander.ParameterException; //導入依賴的package包/類
public void validate(String name, String value)
    throws ParameterException {
  int n = Integer.parseInt(value);
  if (n < 0) {
    throw new ParameterException("Parameter " + name
        + " should be positive (found " + value +")");
  }
}
 
開發者ID:georghinkel,項目名稱:ttc2017smartGrids,代碼行數:9,代碼來源:PositiveInteger.java


注:本文中的com.beust.jcommander.ParameterException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。