Example usage for org.apache.commons.text StrTokenizer getTokenArray

List of usage examples for org.apache.commons.text StrTokenizer getTokenArray

Introduction

In this page you can find the example usage for org.apache.commons.text StrTokenizer getTokenArray.

Prototype

public String[] getTokenArray() 

Source Link

Document

Gets a copy of the full token list as an independent modifiable array.

Usage

From source file:com.twosigma.beakerx.kernel.magic.command.functionality.MagicCommandUtils.java

public static String[] splitPath(String command) {
    StrTokenizer tokenizer = new StrTokenizer(command, StrMatcher.spaceMatcher(), StrMatcher.quoteMatcher());
    return tokenizer.getTokenArray();
}

From source file:com.twosigma.beakerx.kernel.magic.command.functionality.TimeMagicCommand.java

protected TimeItOption buildTimeItOption(Code code) {
    TimeItOption timeItOption = new TimeItOption();

    try {//from   w w  w. j  av  a 2s .co  m
        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;
}