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

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

Introduction

In this page you can find the example usage for org.apache.commons.lang.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:it.jnrpe.utils.StringUtils.java

/**
 * Splits the given string using as separator the <code>separator</code>
 * character.//from ww  w .j  a v a2s . c  o m
 * 
 * @param string
 *            The string to be splitted
 * @param separator
 *            The separator character
 * @param ignoreQuotes
 *            <code>true</code> if the quotes must be ignored.
        
 * @return The splitted string */
public static String[] split(final String string, final char separator, final boolean ignoreQuotes) {
    StrTokenizer strtok = new StrTokenizer(string, StrMatcher.charMatcher(separator),
            StrMatcher.quoteMatcher());
    return strtok.getTokenArray();
}

From source file:com.manydesigns.elements.util.Util.java

public static String[] matchStringArray(String text) {
    StrTokenizer strTokenizer = StrTokenizer.getCSVInstance(text);
    return strTokenizer.getTokenArray();
}

From source file:de.tudarmstadt.ukp.dkpro.tc.core.util.ReportUtils.java

/**
 * Adds results from a serialized matrix to a map
 * //w  ww.j av  a  2 s .com
 * @param aggregateMap
 * @param matrix
 *            a csv matrix with the class names in the first row and first column
 * @return updated map
 * @throws IOException
 */
public static Map<List<String>, Double> updateAggregateMatrix(Map<List<String>, Double> aggregateMap,
        File matrix) throws IOException {
    List<String> confMatrixLines = FileUtils.readLines(matrix);
    StrTokenizer l = StrTokenizer.getCSVInstance(confMatrixLines.get(0));
    l.setDelimiterChar(',');
    String[] headline = l.getTokenArray();

    for (int i = 1; i < confMatrixLines.size(); i++) {
        for (int j = 1; j < headline.length; j++) {
            StrTokenizer line = StrTokenizer.getCSVInstance(confMatrixLines.get(i));
            String pred = headline[j];
            line.setDelimiterChar(',');
            String act = line.getTokenArray()[0];
            double value = Double.valueOf(line.getTokenArray()[j]);

            List<String> key = new ArrayList<String>(Arrays.asList(new String[] { pred, act }));

            if (aggregateMap.get(key) != null) {
                aggregateMap.put(key, aggregateMap.get(key) + value);
            } else {
                aggregateMap.put(key, value);
            }
        }
    }
    return aggregateMap;
}

From source file:com.savy3.util.DBConfiguration.java

/**
 * Converts a String back to connection parameters.
 * @param input String from configuration
 * @return JDBC connection parameters// w w  w .  j  a v a2s. c  om
 */
protected static Properties propertiesFromString(String input) {
    if (input != null && !input.isEmpty()) {
        Properties result = new Properties();
        StrTokenizer propertyTokenizer = StrTokenizer.getCSVInstance(input);
        StrTokenizer valueTokenizer = StrTokenizer.getCSVInstance();
        valueTokenizer.setDelimiterChar('=');
        while (propertyTokenizer.hasNext()) {
            valueTokenizer.reset(propertyTokenizer.nextToken());
            String[] values = valueTokenizer.getTokenArray();
            if (values.length == 2) {
                result.put(values[0], values[1]);
            }
        }
        return result;
    } else {
        return null;
    }
}

From source file:it.drwolf.ridire.session.async.Mapper.java

@SuppressWarnings("unchecked")
public static Integer countWordsFromPoSTagResource(String posTagResourceFileName) throws IOException {
    List<String> lines = FileUtils.readLines(new File(posTagResourceFileName));
    Integer count = 0;//from   w w w.  j  av  a 2  s.c  o m
    StrTokenizer tokenizer = StrTokenizer.getTSVInstance();
    for (String l : lines) {
        tokenizer.reset(l);
        String[] tokens = tokenizer.getTokenArray();
        if (tokens.length == 3) {
            if (Mapper.isValidPos(tokens[1].trim())) {
                ++count;
            }
        }
    }
    return count;
}

From source file:com.haulmont.cuba.core.sys.AbstractAppContextLoader.java

protected void initAppContext() {
    String configProperty = AppContext.getProperty(SPRING_CONTEXT_CONFIG);
    if (StringUtils.isBlank(configProperty)) {
        throw new IllegalStateException("Missing " + SPRING_CONTEXT_CONFIG + " application property");
    }//from   w  w  w.j a  va2 s . c  om

    StrTokenizer tokenizer = new StrTokenizer(configProperty);
    String[] locations = tokenizer.getTokenArray();
    replaceLocationsFromConf(locations);

    ApplicationContext appContext = createApplicationContext(locations);
    AppContext.Internals.setApplicationContext(appContext);

    Events events = AppBeans.get(Events.NAME);
    events.publish(new AppContextInitializedEvent(appContext));

    log.debug("AppContext initialized");
}

From source file:com.haulmont.cuba.core.sys.AppPropertiesTest.java

@Test
public void testEmptyStringSubstitution() {
    AppProperties appProperties = new AppProperties(new AppComponents("test"));
    appProperties.setProperty("refapp.myConfig", "1.xml ${ext.myConfig} 2.xml");
    appProperties.setProperty("ext.myConfig", "");

    String propValue = appProperties.getProperty("refapp.myConfig");
    log.debug("Property value: '" + propValue + "'");

    StrTokenizer tokenizer = new StrTokenizer(propValue);
    String[] locations = tokenizer.getTokenArray();

    Assert.assertArrayEquals(new String[] { "1.xml", "2.xml" }, locations);
}

From source file:com.haulmont.cuba.core.sys.DefaultPermissionValuesConfig.java

protected void init() {
    permissionValues.clear();/*from www. j  a  va2s. c o m*/

    String configName = AppContext.getProperty("cuba.defaultPermissionValuesConfig");
    if (!StringUtils.isBlank(configName)) {
        StrTokenizer tokenizer = new StrTokenizer(configName);
        for (String fileName : tokenizer.getTokenArray()) {
            parseConfigFile(fileName);
        }
    }
}

From source file:com.haulmont.cuba.gui.app.core.credits.CreditsLoader.java

public CreditsLoader load() {
    String configProperty = AppContext.getProperty("cuba.creditsConfig");
    if (StringUtils.isBlank(configProperty)) {
        log.info("Property cuba.creditsConfig is empty");
        return this;
    }//from  w  w  w . j ava2  s .  co m

    StrTokenizer tokenizer = new StrTokenizer(configProperty);
    String[] locations = tokenizer.getTokenArray();

    for (String location : locations) {
        Resources resources = AppBeans.get(Resources.NAME);
        String xml = resources.getResourceAsString(location);
        if (xml == null) {
            log.debug("Resource {} not found, ignore it", location);
            continue;
        }
        Element rootElement = Dom4j.readDocument(xml).getRootElement();
        loadLicenses(rootElement);
        loadConfig(rootElement);
    }

    Collections.sort(items);

    return this;
}

From source file:it.jnrpe.server.console.CommandExecutor.java

public boolean executeCommand(String commandLine) throws Exception {
    StrTokenizer strtok = new StrTokenizer(commandLine, StrMatcher.charMatcher(' '), StrMatcher.quoteMatcher());
    String[] tokensAry = strtok.getTokenArray();
    String commandName = tokensAry[0];
    String[] params;/*from   w  ww  .j a  va 2  s . c  om*/
    if (tokensAry.length == 1) {
        params = new String[0];
    } else {
        params = new String[tokensAry.length - 1];
        System.arraycopy(tokensAry, 1, params, 0, params.length);
    }

    IConsoleCommand command = getCommand(commandName);
    if (command != null) {
        return command.execute(params);
    } else {
        throw new UnknownCommandException("Unknown command :'" + commandName + "'");
    }
}