List of usage examples for com.google.common.base Splitter splitToList
@CheckReturnValue
@Beta
public List<String> splitToList(CharSequence sequence)
From source file:com.haulmont.cuba.core.sys.AppComponents.java
private void load(AppComponent component) { try {//ww w . ja v a2 s. c om 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 : Dom4j.elements(doc.getRootElement(), "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 : Dom4j.elements(moduleEl, "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) { String newValue = 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 += " " + part; } component.setProperty(name, newValue, true); } else { component.setProperty(name, cleanValue, true); } } } } } catch (IOException | DocumentException e) { throw new RuntimeException("Error loading app component '" + component + "'", e); } }
From source file:gobblin.source.extractor.extract.restapi.RestApiExtractor.java
@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;// w w w .j a v a2 s. c o m 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 | RestApiConnectionException | RestApiProcessingException | IOException | SchemaException e) { throw new SchemaException("Failed to get schema using rest api; error - " + e.getMessage(), e); } }
From source file:com.teamhooman.hoomanbot.markov.MarkovGenerator.java
/** * Adds a new sentence to the 'brain'/* w ww. j a va2 s. c o m*/ */ public void add(CharSequence input) { Map<CharMatcher, CharMatcher> swap = ImmutableMap.of(wordMatcher, nonWordMatcher, nonWordMatcher, wordMatcher); CharMatcher matcher = wordMatcher; List<String> parts = Lists.newArrayList(); // input.chars().spliterator(). Splitter sentenceSplitter = Splitter.on(wordMatcher.negate()).trimResults(whitespaceMatcher) .omitEmptyStrings(); List<String> split = sentenceSplitter.splitToList(input); logger.info("Processed:\n\t" + "Input: {}\n\t" + "Words: {}", input, split); if (split.size() < 4) { logger.warn("Sentence was not long enough to learn from."); return; } for (int n = 0; n < split.size() - 3; ++n) { List<String> subList = split.subList(n, n + 4); ListQuad lq = new ListQuad(subList); if (listQuads.containsKey(lq)) { lq = listQuads.get(lq); } else { listQuads.put(lq, lq); } if (n == 0) { lq.setCanStart(true); } if (n == split.size() - 4) { lq.setCanEnd(true); } for (int q = 0; q < 4; ++q) { String token = split.get(n + q); addAssociation(wordToQuads, token, lq); logger.info("Added word-to-containing-quad association: {} / {}", token, lq); } if (n > 0) { String previousToken = split.get(n - 1); addAssociation(quadToPreviousWord, lq, previousToken); logger.info("Added quad-to-possible-predecessor association: {} / {}", previousToken, lq); } if (n < split.size() - 4) { String nextToken = split.get(n + 4); addAssociation(quadToNextWord, lq, nextToken); logger.info("Added quad-to-possible-successor association: {} / {}", nextToken, lq); } } }
From source file:org.apache.gobblin.elasticsearch.writer.ElasticsearchWriterBase.java
ElasticsearchWriterBase(Config config) throws UnknownHostException { this.indexName = config.getString(ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_INDEX_NAME); Preconditions.checkNotNull(this.indexName, "Index Name not provided. Please set " + ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_INDEX_NAME); Preconditions.checkArgument(this.indexName.equals(this.indexName.toLowerCase()), "Index name must be lowercase, you provided " + this.indexName); this.indexType = config.getString(ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_INDEX_TYPE); Preconditions.checkNotNull(this.indexName, "Index Type not provided. Please set " + ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_INDEX_TYPE); this.idMappingEnabled = ConfigUtils.getBoolean(config, ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_ID_MAPPING_ENABLED, ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_ID_MAPPING_DEFAULT); this.idFieldName = ConfigUtils.getString(config, ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_ID_FIELD, ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_ID_FIELD_DEFAULT); String typeMapperClassName = ConfigUtils.getString(config, ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_TYPEMAPPER_CLASS, ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_TYPEMAPPER_CLASS_DEFAULT); if (typeMapperClassName.isEmpty()) { throw new IllegalArgumentException(this.getClass().getCanonicalName() + " needs to be configured with " + ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_TYPEMAPPER_CLASS + " to enable type mapping"); }//from w w w. j a v a 2 s .c o m try { Class<?> typeMapperClass = (Class<?>) Class.forName(typeMapperClassName); this.typeMapper = (TypeMapper) ConstructorUtils.invokeConstructor(typeMapperClass); this.typeMapper.configure(config); this.serializer = this.typeMapper.getSerializer(); } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { log.error("Failed to instantiate type-mapper from class " + typeMapperClassName, e); throw Throwables.propagate(e); } this.malformedDocPolicy = MalformedDocPolicy.valueOf(ConfigUtils.getString(config, ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_MALFORMED_DOC_POLICY, ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_MALFORMED_DOC_POLICY_DEFAULT)); // If list is empty, connect to the default host and port if (!config.hasPath(ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_HOSTS)) { InetSocketTransportAddress hostAddress = new InetSocketTransportAddress( InetAddress.getByName(ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_DEFAULT_HOST), getDefaultPort()); this.hostAddresses = new ArrayList<>(1); this.hostAddresses.add(hostAddress); log.info("Adding host {} to Elasticsearch writer", hostAddress); } else { // Get list of hosts List<String> hosts = ConfigUtils.getStringList(config, ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_HOSTS); // Add host addresses Splitter hostSplitter = Splitter.on(":").trimResults(); this.hostAddresses = new ArrayList<>(hosts.size()); for (String host : hosts) { List<String> hostSplit = hostSplitter.splitToList(host); Preconditions.checkArgument(hostSplit.size() == 1 || hostSplit.size() == 2, "Malformed host name for Elasticsearch writer: " + host + " host names must be of form [host] or [host]:[port]"); InetAddress hostInetAddress = InetAddress.getByName(hostSplit.get(0)); InetSocketTransportAddress hostAddress = null; if (hostSplit.size() == 1) { hostAddress = new InetSocketTransportAddress(hostInetAddress, this.getDefaultPort()); } else if (hostSplit.size() == 2) { hostAddress = new InetSocketTransportAddress(hostInetAddress, Integer.parseInt(hostSplit.get(1))); } this.hostAddresses.add(hostAddress); log.info("Adding host {} to Elasticsearch writer", hostAddress); } } }
From source file:org.apache.james.jmap.methods.SetMessagesCreationProcessor.java
private Set<MessageProperties.MessageProperty> collectMessageProperties( List<ValidationResult> validationErrors) { Splitter propertiesSplitter = Splitter.on(',').trimResults().omitEmptyStrings(); return validationErrors.stream().flatMap(err -> propertiesSplitter.splitToList(err.getProperty()).stream()) .flatMap(MessageProperty::find).collect(Collectors.toSet()); }
From source file:com.facebook.buck.cli.ExopackageInstaller.java
@VisibleForTesting static Optional<PackageInfo> parsePackageInfo(String packageName, String lines) { final String packagePrefix = " Package [" + packageName + "] ("; final String otherPrefix = " Package ["; boolean sawPackageLine = false; final Splitter splitter = Splitter.on('=').limit(2); String codePath = null;/* ww w . j a va2s . c o m*/ String resourcePath = null; String nativeLibPath = null; String versionCode = null; for (String line : Splitter.on("\r\n").split(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; 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.absent(); } 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"); } return Optional.of(new PackageInfo(codePath, nativeLibPath, versionCode)); }
From source file:com.google.gwt.benchmark.dashboard.client.ui.GraphComposite.java
private boolean parseHistory(String token) { if (!token.startsWith("!graph?")) { history.newItem("", true); return false; }// ww w. j a v a2 s . co m token = token.substring("!graph?".length()); Map<String, String> split = null; try { split = Splitter.on("&").withKeyValueSeparator("=").split(token); } catch (IllegalArgumentException e) { history.newItem("", true); return false; } benchmarkName = split.get("benchmark"); if (benchmarkName == null) { history.newItem("", true); return false; } String weekString = split.get("w"); String yearString = split.get("y"); if (weekString == null || yearString == null) { year = -1; week = -1; runnerIds = new TreeSet<>(); return true; } week = Integer.parseInt(weekString); year = Integer.parseInt(yearString); Splitter splitter = Splitter.on(",").trimResults(CharMatcher.anyOf("[]").or(CharMatcher.WHITESPACE)); runnerIds = new TreeSet<String>(splitter.splitToList(split.get("rids"))); return true; }
From source file:fi.johannes.kata.ocr.cells.CellRow.java
/** * Reads from list of lines//from w w w.j a va2 s .c o m * * @param ls * @return */ private List<Cell> readFromList(List<String> ls) { List<Cell> tCell = new ArrayList<>(); Splitter rowSplitter; if (cellsOnRow != -1) { rowSplitter = Splitter.fixedLength(cellsOnRow * celllength); } else { rowSplitter = Splitter.fixedLength(ls.get(0).length()); } Splitter cellSplitter = Splitter.fixedLength(celllength); ; for (String line : ls) { String fixedWidthLine = rowSplitter.splitToList(line).get(0); List<String> parts = cellSplitter.splitToList(fixedWidthLine); for (int i = 0; i < parts.size(); i++) { // if cell doesn't exist yet create try { tCell.get(i).append(parts.get(i)); } catch (IndexOutOfBoundsException e) { Cell newCell = new Cell(); newCell.append(parts.get(i)); tCell.add(i, newCell); } } // otherwise append } return tCell; }
From source file:edu.buaa.satla.analysis.core.CPAchecker.java
private CFA parse(String fileNamesCommaSeparated, MainCPAStatistics stats) throws InvalidConfigurationException, IOException, ParserException, InterruptedException { // parse file and create CFA CFACreator cfaCreator = new CFACreator(config, logger, shutdownNotifier); stats.setCFACreator(cfaCreator);/*from w w w. ja va 2s . com*/ Splitter commaSplitter = Splitter.on(',').omitEmptyStrings().trimResults(); CFA cfa = cfaCreator.parseFileAndCreateCFA(commaSplitter.splitToList(fileNamesCommaSeparated)); stats.setCFA(cfa); return cfa; }
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 . j a v a 2s .c om*/ return newColumn; }