use of org.apache.commons.text.StrTokenizer in project beakerx by twosigma.
the class TimeMagicCommand method buildTimeItOption.
protected TimeItOption buildTimeItOption(Code code) {
TimeItOption timeItOption = new TimeItOption();
try {
StrTokenizer tokenizer = new StrTokenizer(code.asString());
CommandLineParser parser = new PosixParser();
CommandLine cmd = parser.parse(createForTimeIt(), tokenizer.getTokenArray());
if (cmd.hasOption('n')) {
timeItOption.setNumber(Integer.valueOf(cmd.getOptionValue('n')));
}
if (cmd.hasOption('r')) {
timeItOption.setRepeat(Integer.valueOf(cmd.getOptionValue('r')));
}
if (cmd.hasOption('q')) {
timeItOption.setQuietMode(true);
}
} catch (ParseException e) {
throw new IllegalArgumentException(e.getMessage());
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Expected value must be a number " + e.getMessage().toLowerCase());
}
return timeItOption;
}
Aggregations