Java Code Examples for com.google.common.base.Splitter#splitToList()
The following examples show how to use
com.google.common.base.Splitter#splitToList() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringMapFunctions.java From tablesaw with Apache License 2.0 | 6 votes |
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); } return newColumn; }
Example 2
Source File: WorkspaceStatusAction.java From bazel with Apache License 2.0 | 6 votes |
/** * Parses the output of the workspace status action. * * <p>The output is a text file with each line representing a workspace status info key. The key * is the part of the line before the first space and should consist of the characters [A-Z_] * (although this is not checked). Everything after the first space is the value. */ public static Map<String, String> parseValues(Path file) throws IOException { HashMap<String, String> result = new HashMap<>(); Splitter lineSplitter = Splitter.on(' ').limit(2); for (String line : Splitter.on('\n').split(new String(FileSystemUtils.readContentAsLatin1(file)))) { List<String> items = lineSplitter.splitToList(line); if (items.size() != 2) { continue; } result.put(items.get(0), items.get(1)); } return ImmutableMap.copyOf(result); }
Example 3
Source File: StringMapFunctions.java From tablesaw with Apache License 2.0 | 6 votes |
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); } return newColumn; }
Example 4
Source File: StringMapFunctions.java From tablesaw with Apache License 2.0 | 6 votes |
/** * Splits on Whitespace and returns the lexicographically sorted result. * * @return a {@link StringColumn} */ 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; }
Example 5
Source File: StringMapFunctions.java From tablesaw with Apache License 2.0 | 6 votes |
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); } return newColumn; }
Example 6
Source File: CassandraConfiguration.java From cassandra-jdbc-driver with Apache License 2.0 | 6 votes |
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)); } } config.hosts = sb.deleteCharAt(sb.length() - 1).toString(); config.port = tentativePort; // update timeouts config.connectionTimeout = config.connectionTimeout * 1000; config.readTimeout = config.readTimeout * 1000; }
Example 7
Source File: StringMapFunctions.java From tablesaw with Apache License 2.0 | 6 votes |
/** * Splits on Whitespace and returns the lexicographically sorted result. * * @return a {@link StringColumn} */ 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; }
Example 8
Source File: StringMapFunctions.java From tablesaw with Apache License 2.0 | 6 votes |
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); } return newColumn; }
Example 9
Source File: AbstractUnleashMojo.java From unleash-maven-plugin with Eclipse Public License 1.0 | 6 votes |
@MojoProduces @Named("releaseArgs") @MojoInject private Properties getReleaseArgs() { Properties args = new Properties(); Splitter splitter = Splitter.on('='); if (this.releaseArgs != null) { for (String arg : this.releaseArgs) { List<String> split = splitter.splitToList(arg); if (split.size() == 2) { args.put(split.get(0), split.get(1)); } else { args.put(split.get(0), "true"); getLog().info("Detected release argument without an explicit value. Assuming '" + split.get(0) + "' to be a boolean property and setting it to true."); } } } // Add default property indicating that the unleash plugin is triggering the build args.put("isUnleashBuild", "true"); return args; }
Example 10
Source File: EntityReferences.java From greenbeans with Apache License 2.0 | 6 votes |
private static ListMultimap<String, String> readEntityReferences() { ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder(); try { BufferedReader reader = new BufferedReader(new InputStreamReader( EntityReferences.class.getResourceAsStream("entity-references.txt"), Charsets.UTF_8)); //$NON-NLS-1$ try { Splitter splitter = Splitter.on(CharMatcher.WHITESPACE).trimResults().omitEmptyStrings(); String line; while ((line = reader.readLine()) != null) { List<String> lineItems = splitter.splitToList(line); checkState(lineItems.size() > 1); for (int x = 1; x < lineItems.size(); ++x) { builder.put(lineItems.get(0), lineItems.get(x)); } } } finally { reader.close(); } } catch (IOException e) { throw Throwables.propagate(e); } return builder.build(); }
Example 11
Source File: BaseChecker.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
@SneakyThrows public void check(String sql, String expectedRes) { ResultSet resultSet = statement.executeQuery(sql); String s = TextConvertor.dumpResultSet(resultSet).replaceAll("\n", "").replaceAll("\r", ""); System.out.println(s); if (!expectedRes.startsWith("(")) { expectedRes = "(" + expectedRes + ")"; } if (!s.startsWith("(")) { s = "(" + s + ")"; } Splitter on = Splitter.on(")("); List<String> expected = on.splitToList(expectedRes); List<String> result = on.splitToList(s); if (!expectedRes.equals(s)){ HashSet<String> x = toCollection(expected); HashSet<String> y = toCollection(result); Assert.assertEquals(x, y); } }
Example 12
Source File: DDBConnectorCustomizerQuery.java From syndesis with Apache License 2.0 | 6 votes |
@Override protected void customize(Exchange exchange, Map<String, Object> options) { Map<String, AttributeValue> element = Util.getAttributeValueMap("element", options); exchange.getIn().setHeader(DdbConstants.KEY, element); exchange.getIn().setHeader(DdbConstants.OPERATION, DdbOperations.GetItem); List<String> attributes = new ArrayList<String>(); String optionAttributes = ConnectorOptions.extractOption(options, "attributes", ""); if (!optionAttributes.isEmpty()) { Splitter splitter = Splitter.on(','); splitter = splitter.trimResults(); splitter = splitter.omitEmptyStrings(); attributes = splitter.splitToList(optionAttributes); } //fallback to use the list of attributes on the filter if (attributes.isEmpty()) { attributes.addAll(element.keySet()); } exchange.getIn().setHeader(DdbConstants.ATTRIBUTE_NAMES, attributes); LOG.trace("Attributes: " + attributes); }
Example 13
Source File: ProjectWorkspace.java From buck with Apache License 2.0 | 6 votes |
/** * Parses the output of a --show-output build command into an easy to use map. * * @param stdout The stdout of the --show-output build command. * @return The map of target => target output string. The value is relative to the Buck root of * the invoked command. */ public ImmutableMap<String, String> parseShowOutputStdoutAsStrings(String stdout) { List<String> lines = Splitter.on(CharMatcher.anyOf(System.lineSeparator())) .trimResults() .omitEmptyStrings() .splitToList(stdout); Splitter lineSplitter = Splitter.on(' ').trimResults(); ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); for (String line : lines) { List<String> fields = lineSplitter.splitToList(line); assertThat( String.format("Target %s has no outputs.", fields.isEmpty() ? "" : fields.get(0)), fields, Matchers.hasSize(2)); builder.put(fields.get(0), fields.get(1)); } return builder.build(); }
Example 14
Source File: StringMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
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()); } return newColumn; }
Example 15
Source File: Depluralizer.java From immutables with Apache License 2.0 | 5 votes |
DictionaryAidedDepluralizer(String[] exceptions) { Map<String, String> map = Maps.newHashMapWithExpectedSize(exceptions.length); Splitter splitter = Splitter.on(':'); for (String s : exceptions) { List<String> parts = splitter.splitToList(s.toLowerCase()); if (parts.size() == 1) { // simple no-depluratization exception map.put(parts.get(0), parts.get(0)); } else if (parts.size() == 2) { // singular, then plural, so mapping plural->singular map.put(parts.get(1), parts.get(0)); } } this.dictionary = ImmutableMap.copyOf(map); }
Example 16
Source File: AvroUtils.java From incubator-gobblin with Apache License 2.0 | 5 votes |
public static Map<String, Object> getMultiFieldValue(GenericRecord record, String fieldLocation) { Preconditions.checkNotNull(record); Preconditions.checkArgument(!Strings.isNullOrEmpty(fieldLocation)); Splitter splitter = Splitter.on(FIELD_LOCATION_DELIMITER).omitEmptyStrings().trimResults(); List<String> pathList = splitter.splitToList(fieldLocation); if (pathList.size() == 0) { return Collections.emptyMap(); } HashMap<String, Object> retVal = new HashMap<String, Object>(); AvroUtils.getFieldHelper(retVal, record, pathList, 0); return retVal; }
Example 17
Source File: StringMapFunctions.java From tablesaw with Apache License 2.0 | 5 votes |
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()); } return newColumn; }
Example 18
Source File: AppComponents.java From cuba with Apache License 2.0 | 4 votes |
private void load(AppComponent component) { Document doc = getDescriptorDoc(component); String dependsOnAttr = doc.getRootElement().attributeValue("dependsOn"); if (!StringUtils.isEmpty(dependsOnAttr)) { for (String depCompId : splitCommaSeparatedValue(dependsOnAttr)) { AppComponent depComp = get(depCompId); if (depComp == null) { depComp = new AppComponent(depCompId); load(depComp); components.add(depComp); } component.addDependency(depComp); } } for (Element moduleEl : doc.getRootElement().elements("module")) { String blocksAttr = moduleEl.attributeValue("blocks"); if (StringUtils.isEmpty(blocksAttr)) { continue; } List<String> blocks = splitCommaSeparatedValue(blocksAttr); if (blocks.contains("*") || blocks.contains(block)) { for (Element propertyEl : moduleEl.elements("property")) { String name = propertyEl.attributeValue("name"); String value = propertyEl.attributeValue("value"); String existingValue = component.getProperty(name); if (value.startsWith("\\+")) { if (existingValue != null) { log.debug("Overwrite value of property {} from {} to {}", name, existingValue, value); } component.setProperty(name, value.substring(1), false); continue; } if (!value.startsWith("+")) { if (existingValue != null) { log.debug("Overwrite value of property {} from {} to {}", name, existingValue, value); } component.setProperty(name, value, false); continue; } String cleanValue = value.substring(1); if (existingValue != null) { StringBuilder newValue = new StringBuilder(existingValue); Splitter splitter = Splitter.on(AppProperties.SEPARATOR_PATTERN).omitEmptyStrings(); List<String> existingParts = splitter.splitToList(existingValue); for (String part : splitter.split(cleanValue)) { if (!existingParts.contains(part)) { newValue.append(" ").append(part); } } component.setProperty(name, newValue.toString(), true); } else { component.setProperty(name, cleanValue, true); } } } } }
Example 19
Source File: RestApiExtractor.java From incubator-gobblin with Apache License 2.0 | 4 votes |
@Override public void extractMetadata(String schema, String entity, WorkUnit workUnit) throws SchemaException { log.info("Extract Metadata using Rest Api"); JsonArray columnArray = new JsonArray(); String inputQuery = workUnitState.getProp(ConfigurationKeys.SOURCE_QUERYBASED_QUERY); List<String> columnListInQuery = null; JsonArray array = null; if (!Strings.isNullOrEmpty(inputQuery)) { columnListInQuery = Utils.getColumnListFromQuery(inputQuery); } String excludedColumns = workUnitState.getProp(ConfigurationKeys.SOURCE_QUERYBASED_EXCLUDED_COLUMNS); List<String> columnListExcluded = ImmutableList.<String> of(); if (Strings.isNullOrEmpty(inputQuery) && !Strings.isNullOrEmpty(excludedColumns)) { Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults(); columnListExcluded = splitter.splitToList(excludedColumns.toLowerCase()); } try { boolean success = this.connector.connect(); if (!success) { throw new SchemaException("Failed to connect."); } log.debug("Connected successfully."); List<Command> cmds = this.getSchemaMetadata(schema, entity); CommandOutput<?, ?> response = this.connector.getResponse(cmds); array = this.getSchema(response); for (JsonElement columnElement : array) { Schema obj = GSON.fromJson(columnElement, Schema.class); String columnName = obj.getColumnName(); obj.setWaterMark(this.isWatermarkColumn(workUnitState.getProp("extract.delta.fields"), columnName)); if (this.isWatermarkColumn(workUnitState.getProp("extract.delta.fields"), columnName)) { obj.setNullable(false); } else if (this.getPrimarykeyIndex(workUnitState.getProp("extract.primary.key.fields"), columnName) == 0) { // set all columns as nullable except primary key and watermark columns obj.setNullable(true); } obj.setPrimaryKey(this.getPrimarykeyIndex(workUnitState.getProp("extract.primary.key.fields"), columnName)); String jsonStr = GSON.toJson(obj); JsonObject jsonObject = GSON.fromJson(jsonStr, JsonObject.class).getAsJsonObject(); // If input query is null or provided '*' in the query select all columns. // Else, consider only the columns mentioned in the column list if (inputQuery == null || columnListInQuery == null || (columnListInQuery.size() == 1 && columnListInQuery.get(0).equals("*")) || (columnListInQuery.size() >= 1 && this.isMetadataColumn(columnName, columnListInQuery))) { if (!columnListExcluded.contains(columnName.trim().toLowerCase())) { this.columnList.add(columnName); columnArray.add(jsonObject); } } } this.updatedQuery = buildDataQuery(inputQuery, entity); log.info("Schema:" + columnArray); this.setOutputSchema(columnArray); } catch (RuntimeException | RestApiProcessingException | RestApiConnectionException | IOException | SchemaException e) { throw new SchemaException("Failed to get schema using rest api; error - " + e.getMessage(), e); } }
Example 20
Source File: MoreStringUtilTest.java From vjtools with Apache License 2.0 | 4 votes |
@Test public void split() { List<String> result = MoreStringUtil.split("192.168.0.1", '.', 4); assertThat(result).hasSize(4).containsSequence("192", "168", "0", "1"); result = MoreStringUtil.split("192.168..1", '.', 4); assertThat(result).hasSize(3).containsSequence("192", "168", "1"); result = MoreStringUtil.split("192.168.0.", '.', 4); assertThat(result).hasSize(3).containsSequence("192", "168", "0"); assertThat(MoreStringUtil.split(null, '.', 4)).isNull(); assertThat(MoreStringUtil.split("", '.', 4)).hasSize(0); Splitter splitter =MoreStringUtil.charsSplitter("/\\").omitEmptyStrings(); result = splitter.splitToList("/a/b/c"); assertThat(result).hasSize(3).containsSequence("a", "b", "c"); result = splitter.splitToList("\\a\\b\\c"); assertThat(result).hasSize(3).containsSequence( "a", "b", "c"); }