List of usage examples for com.google.common.base Splitter omitEmptyStrings
boolean omitEmptyStrings
To view the source code for com.google.common.base Splitter omitEmptyStrings.
Click Source Link
From source file:org.bitstrings.maven.plugins.portallocator.util.Helpers.java
public static Iterable<String> iterateOnSplit(String text, String separator, boolean omitEmpty) { final Splitter splitter = Splitter.on(separator).trimResults(); if (omitEmpty) { splitter.omitEmptyStrings(); }/*from w ww . ja v a 2s . c o m*/ return splitter.split(text); }
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 w w . j a va 2 s. 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:de.ii.xtraplatform.feature.transformer.api.FeatureTypeMapping.java
private List<String> splitPath(String path) { Splitter splitter = path.contains("http://") ? Splitter.onPattern("\\/(?=http)") : Splitter.on("/"); return splitter.omitEmptyStrings().splitToList(path); }
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()); }//from ww w . j a va 2 s . c om 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);// w w w . jav a 2 s .co 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 . j a v a 2 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 ww w . j a v a 2s. 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}//from ww w.j ava 2 s . c o 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; }