Search in sources :

Example 1 with StrTokenizer

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;
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) StrTokenizer(org.apache.commons.text.StrTokenizer)

Aggregations

CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 ParseException (org.apache.commons.cli.ParseException)1 PosixParser (org.apache.commons.cli.PosixParser)1 StrTokenizer (org.apache.commons.text.StrTokenizer)1