Java Code Examples for com.google.common.base.Splitter#omitEmptyStrings()

The following examples show how to use com.google.common.base.Splitter#omitEmptyStrings() . 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: DDBConnectorCustomizerQuery.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: StringMapFunctions.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
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 3
Source File: StringMapFunctions.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
/**
 * 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 4
Source File: StringMapFunctions.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
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 5
Source File: StringMapFunctions.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
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: StringMapFunctions.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
/**
 * 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 7
Source File: StringMapFunctions.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
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 8
Source File: StringMapFunctions.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
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 9
Source File: StringMapFunctions.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
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 10
Source File: SplitBuilder.java    From kite with Apache License 2.0 4 votes vote down vote up
public Split(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) {
  super(builder, config, parent, child, context);      
  this.inputFieldName = getConfigs().getString(config, "inputField");
  
  this.outputFieldName = getConfigs().getString(config, "outputField", null);
  this.outputFieldNames = getConfigs().getStringList(config, "outputFields", null);
  if (outputFieldName == null && outputFieldNames == null) {
    throw new MorphlineCompilationException("Either outputField or outputFields must be defined", config);
  }
  if (outputFieldName != null && outputFieldNames != null) {
    throw new MorphlineCompilationException("Must not define both outputField and outputFields at the same time", config);
  }
  
  String separator = getConfigs().getString(config, "separator");
  boolean isRegex = getConfigs().getBoolean(config, "isRegex", false);
  GrokDictionaries dict = new GrokDictionaries(config, getConfigs());
  Splitter currentSplitter;
  if (isRegex) {
    currentSplitter = Splitter.on(dict.compileExpression(separator).pattern());
  } else if (separator.length() == 1) {
    currentSplitter = Splitter.on(separator.charAt(0));
  } else {
    currentSplitter = Splitter.on(separator);
  }
  
  int limit = getConfigs().getInt(config, "limit", -1);
  if (limit > 0) {
    currentSplitter = currentSplitter.limit(limit);
  }
  
  this.addEmptyStrings = getConfigs().getBoolean(config, "addEmptyStrings", false);      
  if (outputFieldNames == null && !addEmptyStrings) {
    currentSplitter = currentSplitter.omitEmptyStrings();
  }
  
  if (getConfigs().getBoolean(config, "trim", true)) {
    currentSplitter = currentSplitter.trimResults();
  }
  
  this.splitter = currentSplitter;
  validateArguments();
}