本文整理汇总了Java中jargs.gnu.CmdLineParser.addDoubleOption方法的典型用法代码示例。如果您正苦于以下问题:Java CmdLineParser.addDoubleOption方法的具体用法?Java CmdLineParser.addDoubleOption怎么用?Java CmdLineParser.addDoubleOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jargs.gnu.CmdLineParser
的用法示例。
在下文中一共展示了CmdLineParser.addDoubleOption方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testStandardOptions
import jargs.gnu.CmdLineParser; //导入方法依赖的package包/类
public void testStandardOptions() throws Exception {
CmdLineParser parser = new CmdLineParser();
CmdLineParser.Option verbose = parser.addBooleanOption('v', "verbose");
CmdLineParser.Option size = parser.addIntegerOption('s', "size");
CmdLineParser.Option name = parser.addStringOption('n', "name");
CmdLineParser.Option fraction = parser.addDoubleOption('f', "fraction");
CmdLineParser.Option missing = parser.addBooleanOption('m', "missing");
CmdLineParser.Option careful = parser.addBooleanOption("careful");
CmdLineParser.Option bignum = parser.addLongOption('b', "bignum");
assertEquals(null, parser.getOptionValue(size));
Long longValue = new Long(new Long(Integer.MAX_VALUE).longValue() + 1);
parser.parse(new String[] { "-v", "--size=100", "-b",
longValue.toString(), "-n", "foo", "-f", "0.1", "rest" },
Locale.US);
assertEquals(null, parser.getOptionValue(missing));
assertEquals(Boolean.TRUE, parser.getOptionValue(verbose));
assertEquals(100, ((Integer) parser.getOptionValue(size)).intValue());
assertEquals("foo", parser.getOptionValue(name));
assertEquals(longValue, parser.getOptionValue(bignum));
assertEquals(0.1, ((Double) parser.getOptionValue(fraction))
.doubleValue(), 0.1e-6);
assertArrayEquals(new String[]{"rest"}, parser.getRemainingArgs());
}
示例2: testExplictlyTerminatedOptions
import jargs.gnu.CmdLineParser; //导入方法依赖的package包/类
public void testExplictlyTerminatedOptions() throws Exception {
CmdLineParser parser = new CmdLineParser();
CmdLineParser.Option alt = parser.addBooleanOption('a', "alt");
CmdLineParser.Option debug = parser.addBooleanOption('d', "debug");
CmdLineParser.Option verbose = parser.addBooleanOption('v', "verbose");
CmdLineParser.Option fraction = parser.addDoubleOption('f', "fraction");
parser.parse(new String[] {
"-a", "hello", "-d", "-f", "10", "--", "goodbye", "-v", "welcome",
"-f", "-10"
});
assertEquals(Boolean.TRUE, parser.getOptionValue(alt));
assertEquals(Boolean.TRUE, parser.getOptionValue(debug));
assertEquals(null, parser.getOptionValue(verbose));
assertEquals(new Double(10), parser.getOptionValue(fraction));
assertArrayEquals(
new String[]{"hello", "goodbye", "-v", "welcome", "-f", "-10"},
parser.getRemainingArgs());
}
示例3: testLocale
import jargs.gnu.CmdLineParser; //导入方法依赖的package包/类
public void testLocale() throws Exception {
CmdLineParser parser = new CmdLineParser();
CmdLineParser.Option fraction = parser.addDoubleOption('f', "fraction");
parser.parse(new String[] { "--fraction=0.2" }, Locale.US);
assertEquals(0.2, ((Double) parser.getOptionValue(fraction))
.doubleValue(), 0.1e-6);
parser.parse(new String[] { "--fraction=0,2" }, Locale.GERMANY);
assertEquals(0.2, ((Double) parser.getOptionValue(fraction))
.doubleValue(), 0.1e-6);
}
示例4: main
import jargs.gnu.CmdLineParser; //导入方法依赖的package包/类
/**
* Main client entry point for stand-alone operation.
*/
public static void main(String[] args) {
BasicConfigurator.configure(new ConsoleAppender(
new PatternLayout("%d [%-25t] %-5p: %m%n")));
CmdLineParser parser = new CmdLineParser();
CmdLineParser.Option help = parser.addBooleanOption('h', "help");
CmdLineParser.Option output = parser.addStringOption('o', "output");
CmdLineParser.Option iface = parser.addStringOption('i', "iface");
CmdLineParser.Option seedTime = parser.addIntegerOption('s', "seed");
CmdLineParser.Option maxUpload = parser.addDoubleOption('u', "max-upload");
CmdLineParser.Option maxDownload = parser.addDoubleOption('d', "max-download");
try {
parser.parse(args);
} catch (CmdLineParser.OptionException oe) {
System.err.println(oe.getMessage());
usage(System.err);
System.exit(1);
}
// Display help and exit if requested
if (Boolean.TRUE.equals((Boolean)parser.getOptionValue(help))) {
usage(System.out);
System.exit(0);
}
String outputValue = (String)parser.getOptionValue(output,
DEFAULT_OUTPUT_DIRECTORY);
String ifaceValue = (String)parser.getOptionValue(iface);
InterfaceName=ifaceValue;
int seedTimeValue = (Integer)parser.getOptionValue(seedTime, -1);
double maxDownloadRate = (Double)parser.getOptionValue(maxDownload, 0.0);
double maxUploadRate = (Double)parser.getOptionValue(maxUpload, 0.0);
String[] otherArgs = parser.getRemainingArgs();
if (otherArgs.length != 1) {
usage(System.err);
System.exit(1);
}
try {
Client c = new Client(
getIPv4Address(ifaceValue),
SharedTorrent.fromFile(
new File(otherArgs[0]),
new File(outputValue)));
c.setMaxDownloadRate(maxDownloadRate);
c.setMaxUploadRate(maxUploadRate);
// Set a shutdown hook that will stop the sharing/seeding and send
// a STOPPED announce request.
Runtime.getRuntime().addShutdownHook(
new Thread(new Client.ClientShutdown(c, null)));
c.share(seedTimeValue);
if (Client.ClientState.ERROR.equals(c.getState())) {
System.exit(1);
}
} catch (Exception e) {
logger.error("Fatal error: {}", e.getMessage(), e);
System.exit(2);
}
}