Example usage for com.google.common.base Splitter trimResults

List of usage examples for com.google.common.base Splitter trimResults

Introduction

In this page you can find the example usage for com.google.common.base Splitter trimResults.

Prototype

@CheckReturnValue
public Splitter trimResults() 

Source Link

Document

Returns a splitter that behaves equivalently to this splitter, but automatically removes leading and trailing CharMatcher#WHITESPACE whitespace from each returned substring; equivalent to trimResults(CharMatcher.WHITESPACE) .

Usage

From source file:com.intel.podm.common.utils.StringRepresentation.java

public static List<String> toList(String stringToSplit, boolean trimResults) {
    Splitter splitter = Splitter.on(ELEMENT_SEPARATOR);

    if (trimResults) {
        splitter = splitter.trimResults();
    }/*  w  w  w.  j a va2  s.  com*/

    return splitter.splitToList(stringToSplit);
}

From source file:com.intel.podm.common.utils.StringRepresentation.java

public static Map<String, String> toMap(String stringToSplit, boolean trimResults, boolean omitEmptyStrings) {
    Splitter splitter = Splitter.on(ELEMENT_SEPARATOR);

    if (trimResults) {
        splitter = splitter.trimResults();
    }/*from  w ww.  jav  a 2s  .c o m*/

    if (omitEmptyStrings) {
        splitter = splitter.omitEmptyStrings();
    }

    Map<String, String> resultMap = splitter.withKeyValueSeparator(KEY_VALUE_SEPARATOR).split(stringToSplit);
    resultMap = new HashMap<>(resultMap);
    convertStringNullValues(resultMap);
    return resultMap;
}

From source file:com.teradata.tempto.internal.convention.tabledefinitions.JdbcDataFileDescriptor.java

public List<List<Object>> getRows() {
    List<List<Object>> values = newArrayList();
    String delimiter = getColumnDelimiter();

    QueryRowMapper rowMapper = new QueryRowMapper(columnTypes);
    Splitter valuesSplitter = Splitter.on(delimiter);
    if (isTrimValues()) {
        valuesSplitter = valuesSplitter.trimResults();
    }// www .  j  a  va2  s.c  om

    for (String line : sqlSectionParsingResult.getContentLines()) {
        List<String> rowValues = parseLine(line, delimiter, valuesSplitter);
        values.add(rowMapper.mapToRow(rowValues).getValues());
    }

    return values;
}

From source file:com.teradata.tempto.convention.SqlResultDescriptor.java

public List<Row> getRows(List<JDBCType> columnTypes) {
    List<Row> values = newArrayList();
    String delimiter = getColumnDelimiter();

    QueryRowMapper rowMapper = new QueryRowMapper(columnTypes);
    Splitter valuesSplitter = Splitter.on(delimiter);
    if (isTrimValues()) {
        valuesSplitter = valuesSplitter.trimResults();
    }//from ww w .j  ava  2 s. co  m

    for (String line : sqlSectionParsingResult.getContentLines()) {
        List<String> rowValues = parseLine(line, delimiter, valuesSplitter);
        values.add(rowMapper.mapToRow(rowValues));
    }

    if (isJoinAllRowsToOne()) {
        checkState(columnTypes.size() == 1,
                "Expected single column result when 'joinAllRowsToOne' property is set, columnTypes: %s",
                columnTypes);
        String joinedRows = values.stream().map(row -> String.valueOf(row.getValues().get(0)))
                .collect(joining("\n"));
        return ImmutableList.of(row(joinedRows));
    }

    return values;
}

From source file:tech.tablesaw.columns.strings.StringMapFunctions.java

default DoubleColumn countTokens(String separator) {
    DoubleColumn newColumn = DoubleColumn.create(name() + "[token count]", this.size());

    for (int r = 0; r < size(); r++) {
        String value = getString(r);

        Splitter splitter = Splitter.on(separator);
        splitter = splitter.trimResults();
        splitter = splitter.omitEmptyStrings();
        List<String> tokens = new ArrayList<>(splitter.splitToList(value));
        newColumn.set(r, tokens.size());
    }//  ww  w  . jav a2 s  . c o m
    return newColumn;
}

From source file:tech.tablesaw.columns.strings.StringMapFunctions.java

default StringColumn tokenizeAndSort(String separator) {
    StringColumn newColumn = StringColumn.create(name() + "[sorted]", this.size());

    for (int r = 0; r < size(); r++) {
        String value = getString(r);

        Splitter splitter = Splitter.on(separator);
        splitter = splitter.trimResults();
        splitter = splitter.omitEmptyStrings();
        List<String> tokens = new ArrayList<>(splitter.splitToList(value));
        Collections.sort(tokens);
        value = String.join(separator, tokens);
        newColumn.set(r, value);//from   w w w . j  ava2  s  .c o  m
    }
    return newColumn;
}

From source file:tech.tablesaw.columns.strings.StringMapFunctions.java

/**
 * Returns a column of arbitrary size containing each token in this column, where a token is defined using the
 * given separator.//from   ww  w.  ja v  a2  s.co m
 *
 * NOTE: Unlike other map functions, this method produces a column whose size may be different from the source,
 * so they cannot safely be combined in a table.
 *
 * @param separator the delimiter used in the tokenizing operation
 * @return          a new column
 */
default StringColumn tokens(String separator) {
    StringColumn newColumn = StringColumn.create(name() + "[token count]");

    for (int r = 0; r < size(); r++) {
        String value = getString(r);
        Splitter splitter = Splitter.on(separator);
        splitter = splitter.trimResults();
        splitter = splitter.omitEmptyStrings();
        List<String> tokens = new ArrayList<>(splitter.splitToList(value));
        for (String token : tokens) {
            newColumn.append(token);
        }
    }
    return newColumn;
}

From source file:tech.tablesaw.columns.strings.StringMapFunctions.java

default StringColumn tokenizeAndRemoveDuplicates(String separator) {
    StringColumn newColumn = StringColumn.create(name() + "[without duplicates]", this.size());

    for (int r = 0; r < size(); r++) {
        String value = getString(r);

        Splitter splitter = Splitter.on(separator);
        splitter = splitter.trimResults();
        splitter = splitter.omitEmptyStrings();
        List<String> tokens = new ArrayList<>(splitter.splitToList(value));

        String result = tokens.stream().distinct().collect(Collectors.joining(separator));
        newColumn.set(r, result);//from   w  w  w .  j a v a  2 s .c om
    }
    return newColumn;
}

From source file:tech.tablesaw.columns.strings.StringMapFunctions.java

/**
 * Splits on Whitespace and returns the lexicographically sorted result.
 *
 * @return a {@link StringColumn}// w  w  w  . ja va  2  s .  co  m
 */
default StringColumn tokenizeAndSort() {
    StringColumn newColumn = StringColumn.create(name() + "[sorted]", this.size());

    for (int r = 0; r < size(); r++) {
        String value = getString(r);
        Splitter splitter = Splitter.on(CharMatcher.whitespace());
        splitter = splitter.trimResults();
        splitter = splitter.omitEmptyStrings();
        List<String> tokens = new ArrayList<>(splitter.splitToList(value));
        Collections.sort(tokens);
        value = String.join(" ", tokens);
        newColumn.set(r, value);
    }
    return newColumn;
}