List of usage examples for com.google.common.base Splitter splitToList
@CheckReturnValue
@Beta
public List<String> splitToList(CharSequence sequence)
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. j ava 2s.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 va2 s .c om * * 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 . ja v a 2 s .c o m } return newColumn; }
From source file:annis.sqlgen.AnnotateSqlGenerator.java
public String getDocumentQuery(long toplevelCorpusID, String documentName, List<String> nodeAnnotationFilter) { TableAccessStrategy tas = createTableAccessStrategy(); List<String> fields = getSelectFields(); boolean filter = false; Set<String> qualifiedNodeAnnos = new LinkedHashSet<>(); Set<String> unqualifiedNodeAnnos = new LinkedHashSet<>(); if (nodeAnnotationFilter != null) { Splitter namespaceSplitter = Splitter.on("::").trimResults().limit(2); filter = true;// w w w .j a v a 2 s . co m for (String anno : nodeAnnotationFilter) { List<String> splitted = namespaceSplitter.splitToList(anno); if (splitted.size() > 1) { qualifiedNodeAnnos.add(AnnotationConditionProvider.regexEscaper.escape(splitted.get(0)) + ":" + AnnotationConditionProvider.regexEscaper.escape(splitted.get(1))); } else { unqualifiedNodeAnnos.add(AnnotationConditionProvider.regexEscaper.escape(splitted.get(0))); } } } StringBuilder template = new StringBuilder(); template.append("SELECT DISTINCT \n" + "\tARRAY[-1::bigint] AS key, ARRAY[''::varchar] AS key_names, 0 as matchstart, " + StringUtils.join(fields, ", ") + ", " + "c.path_name as path, c.path_name[1] as document_name\n" + "FROM\n" + "\tfacts_:top AS facts,\n" + "\tcorpus as c, corpus as toplevel\n" + "WHERE\n" + "\ttoplevel.id = :top AND c.name = :document_name AND " + tas.aliasedColumn(NODE_TABLE, "corpus_ref") + " = c.id\n" + "\tAND toplevel.top_level IS TRUE\n" + "\tAND c.pre >= toplevel.pre AND c.post <= toplevel.post\n"); if (filter) { template.append("\tAND (is_token IS TRUE"); if (!qualifiedNodeAnnos.isEmpty()) { String orExpr = Joiner.on(")|(").join(qualifiedNodeAnnos); template.append(" OR node_qannotext ~ '(^((").append(orExpr).append(")):(.*)$)' "); } if (!unqualifiedNodeAnnos.isEmpty()) { String orExpr = Joiner.on(")|(").join(unqualifiedNodeAnnos); template.append(" OR node_annotext ~ '(^((").append(orExpr).append(")):(.*)$)' "); } template.append(")\n"); } template.append("ORDER BY ").append(tas.aliasedColumn(COMPONENT_TABLE, "name")).append(", ") .append(tas.aliasedColumn(COMPONENT_TABLE, "id")).append(", ") .append(tas.aliasedColumn(RANK_TABLE, "pre")); String sql = template.toString().replace(":top", "" + toplevelCorpusID).replace(":document_name", sqlString(documentName)); return sql; }
From source file:gobblin.azkaban.AzkabanJobLauncher.java
/** * Uses the properties {@link ConfigurationKeys#AZKABAN_EXECUTION_DAYS_LIST}, * {@link ConfigurationKeys#AZKABAN_EXECUTION_TIME_RANGE}, and * {@link TimeRangeChecker#isTimeInRange(List, String, String, DateTime)} to determine if the current job should * continue its execution based on the extra scheduled parameters defined in the config. * * @return true if this job should be launched, false otherwise. *///w w w . j a v a 2 s. c o m private boolean isCurrentTimeInRange() { Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults(); if (this.props.contains(ConfigurationKeys.AZKABAN_EXECUTION_DAYS_LIST) && this.props.contains(ConfigurationKeys.AZKABAN_EXECUTION_TIME_RANGE)) { List<String> executionTimeRange = splitter .splitToList(this.props.getProperty(ConfigurationKeys.AZKABAN_EXECUTION_TIME_RANGE)); List<String> executionDays = splitter .splitToList(this.props.getProperty(ConfigurationKeys.AZKABAN_EXECUTION_DAYS_LIST)); Preconditions.checkArgument(executionTimeRange.size() == 2, "The property " + ConfigurationKeys.AZKABAN_EXECUTION_DAYS_LIST + " should be a comma separated list of two entries"); return TimeRangeChecker.isTimeInRange(executionDays, executionTimeRange.get(0), executionTimeRange.get(1), new DateTime(DateTimeZone.forID(ConfigurationKeys.PST_TIMEZONE_NAME))); } return true; }
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 . j a va 2 s . c om*/ */ 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; }
From source file:org.nmdp.service.epitope.allelecode.NmdpV3AlleleCodeResolver.java
Map<String, AlleleCodeExpansion> buildAlleleCodeMapFromStream(final InputStream inputStream) { try {//from w w w .jav a 2s.c o m Map<String, AlleleCodeExpansion> newMap = new HashMap<>(); int i = 0; Splitter splitter = Splitter.on("\t"); try (InputStreamReader ir = new InputStreamReader(inputStream); BufferedReader br = new BufferedReader(ir)) { while (br.readLine().length() != 0) continue; // skip header String s = null; while ((s = br.readLine()) != null) { List<String> parsed = splitter.splitToList(s); if (parsed.size() != 3) { throw new RuntimeException( "failed to parse file on line " + i + ", expected 3 fields: " + s); } newMap.put(parsed.get(1), new AlleleCodeExpansion(parsed.get(2), ("*".equals(parsed.get(0))))); } } finally { inputStream.close(); } return newMap; } catch (RuntimeException e) { throw (RuntimeException) e; } catch (Exception e) { throw new RuntimeException("exception while refreshing allele codes", e); } }
From source file:com.google.devtools.build.android.desugar.CoreLibrarySupport.java
public CoreLibrarySupport(CoreLibraryRewriter rewriter, ClassLoader targetLoader, List<String> renamedPrefixes, List<String> emulatedInterfaces, List<String> memberMoves, List<String> excludeFromEmulation) { this.rewriter = rewriter; this.targetLoader = targetLoader; checkArgument(renamedPrefixes.stream().allMatch(prefix -> prefix.startsWith("java/")), renamedPrefixes); this.renamedPrefixes = ImmutableSet.copyOf(renamedPrefixes); this.excludeFromEmulation = ImmutableSet.copyOf(excludeFromEmulation); ImmutableSet.Builder<Class<?>> classBuilder = ImmutableSet.builder(); for (String itf : emulatedInterfaces) { checkArgument(itf.startsWith("java/util/"), itf); Class<?> clazz = loadFromInternal(rewriter.getPrefix() + itf); checkArgument(clazz.isInterface(), itf); classBuilder.add(clazz);/*from ww w .ja va 2s .c o m*/ } this.emulatedInterfaces = classBuilder.build(); // We can call isRenamed and rename below b/c we initialized the necessary fields above // Use LinkedHashMap to tolerate identical duplicates LinkedHashMap<String, String> movesBuilder = new LinkedHashMap<>(); Splitter splitter = Splitter.on("->").trimResults().omitEmptyStrings(); for (String move : memberMoves) { List<String> pair = splitter.splitToList(move); checkArgument(pair.size() == 2, "Doesn't split as expected: %s", move); checkArgument(pair.get(0).startsWith("java/"), "Unexpected member: %s", move); int sep = pair.get(0).indexOf('#'); checkArgument(sep > 0 && sep == pair.get(0).lastIndexOf('#'), "invalid member: %s", move); checkArgument(!isRenamedCoreLibrary(pair.get(0).substring(0, sep)), "Original renamed, no need to move it: %s", move); checkArgument(isRenamedCoreLibrary(pair.get(1)), "Target not renamed: %s", move); checkArgument(!this.excludeFromEmulation.contains(pair.get(0)), "Retargeted invocation %s shouldn't overlap with excluded", move); String value = renameCoreLibrary(pair.get(1)); String existing = movesBuilder.put(pair.get(0), value); checkArgument(existing == null || existing.equals(value), "Two move destinations %s and %s configured for %s", existing, value, pair.get(0)); } this.memberMoves = ImmutableMap.copyOf(movesBuilder); }
From source file:com.github.cassandra.jdbc.CassandraConfiguration.java
private void init() { int tentativePort = config.port; Splitter splitter = Splitter.on(':').trimResults().omitEmptyStrings().limit(2); StringBuilder sb = new StringBuilder(); for (String host : Splitter.on(',').trimResults().omitEmptyStrings().split(config.hosts)) { List<String> h = splitter.splitToList(host); sb.append(h.get(0)).append(','); if (h.size() > 1 && tentativePort <= 0) { tentativePort = Ints.tryParse(h.get(1)); }//from w ww .jav a 2 s .c o m } config.hosts = sb.deleteCharAt(sb.length() - 1).toString(); config.port = tentativePort; // update timeouts config.connectionTimeout = config.connectionTimeout * 1000; config.readTimeout = config.readTimeout * 1000; }
From source file:com.facebook.buck.android.ExopackageInstaller.java
@VisibleForTesting static Optional<PackageInfo> parsePathAndPackageInfo(String packageName, String rawOutput) { Iterable<String> lines = Splitter.on(LINE_ENDING).omitEmptyStrings().split(rawOutput); String pmPathPrefix = "package:"; String pmPath = null;//from w w w . j av a 2 s. com for (String line : lines) { // Ignore silly linker warnings about non-PIC code on emulators if (!line.startsWith("WARNING: linker: ")) { pmPath = line; break; } } if (pmPath == null || !pmPath.startsWith(pmPathPrefix)) { LOG.warn("unable to locate package path for [" + packageName + "]"); return Optional.empty(); } final String packagePrefix = " Package [" + packageName + "] ("; final String otherPrefix = " Package ["; boolean sawPackageLine = false; final Splitter splitter = Splitter.on('=').limit(2); String codePath = null; String resourcePath = null; String nativeLibPath = null; String versionCode = null; for (String line : lines) { // Just ignore everything until we see the line that says we are in the right package. if (line.startsWith(packagePrefix)) { sawPackageLine = true; continue; } // This should never happen, but if we do see a different package, stop parsing. if (line.startsWith(otherPrefix)) { break; } // Ignore lines before our package. if (!sawPackageLine) { continue; } // Parse key-value pairs. List<String> parts = splitter.splitToList(line.trim()); if (parts.size() != 2) { continue; } switch (parts.get(0)) { case "codePath": codePath = parts.get(1); break; case "resourcePath": resourcePath = parts.get(1); break; case "nativeLibraryPath": nativeLibPath = parts.get(1); break; // Lollipop uses this name. Not sure what's "legacy" about it yet. // Maybe something to do with 64-bit? // Might need to update if people report failures. case "legacyNativeLibraryDir": nativeLibPath = parts.get(1); break; case "versionCode": // Extra split to get rid of the SDK thing. versionCode = parts.get(1).split(" ", 2)[0]; break; default: break; } } if (!sawPackageLine) { return Optional.empty(); } Preconditions.checkNotNull(codePath, "Could not find codePath"); Preconditions.checkNotNull(resourcePath, "Could not find resourcePath"); Preconditions.checkNotNull(nativeLibPath, "Could not find nativeLibraryPath"); Preconditions.checkNotNull(versionCode, "Could not find versionCode"); if (!codePath.equals(resourcePath)) { throw new IllegalStateException("Code and resource path do not match"); } // Lollipop doesn't give the full path to the apk anymore. Not sure why it's "base.apk". if (!codePath.endsWith(".apk")) { codePath += "/base.apk"; } return Optional.of(new PackageInfo(codePath, nativeLibPath, versionCode)); }