Java Code Examples for com.google.common.base.Joiner#appendTo()

The following examples show how to use com.google.common.base.Joiner#appendTo() . 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: SQLiteStoreImpl.java    From bistoury with GNU General Public License v3.0 7 votes vote down vote up
private static String getDeleteSql(List<String> keys) {
    List<String> newKeys = Lists.transform(keys, new Function<String, String>() {
        @Override
        public String apply(String input) {
            return "'" + input + "'";
        }
    });
    StringBuilder sb = new StringBuilder("delete from bistoury where b_key in (");

    Joiner joiner = Joiner.on(",").skipNulls();

    HashSet<String> set = Sets.newHashSet(newKeys);
    if (set.size() == 0) {
        return null;
    }

    joiner.appendTo(sb, set);
    sb.append(")");
    return sb.toString();
}
 
Example 2
Source File: ObjectProperties.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public String toString()
{
    StringBuilder sb = new StringBuilder();
    Joiner joiner = Joiner.on(",");
    joiner.withKeyValueSeparator("=").appendTo(sb, _properties);
    if (_attributeNames != null && !_attributeNames.isEmpty())
    {
        if (!_properties.isEmpty())
        {
            sb.append(",");
        }
        sb.append("ATTRIBUTES=[");
        joiner.appendTo(sb, _attributeNames);
        sb.append("]");
    }
    return sb.toString();
}
 
Example 3
Source File: ResourceManagerExample.java    From google-cloud-java with Apache License 2.0 6 votes vote down vote up
private static void addUsage(
    String actionName, ResourceManagerAction action, StringBuilder usage) {
  usage.append(actionName);
  Joiner joiner = Joiner.on(" ");
  String[] requiredParams = action.getRequiredParams();
  if (requiredParams.length > 0) {
    usage.append(' ');
    joiner.appendTo(usage, requiredParams);
  }
  String[] optionalParams = action.getOptionalParams();
  if (optionalParams.length > 0) {
    usage.append(" [");
    joiner.appendTo(usage, optionalParams);
    usage.append(']');
  }
}
 
Example 4
Source File: ResourceChangeSet.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public String toString() {
	Joiner joiner = Joiner.on("\n  ");
	StringBuilder result = new StringBuilder();
	result.append("CHANGED:\n  ");
	joiner.appendTo(result, changed);
	result.append("\nDELETED:\n  ");
	joiner.appendTo(result, deleted);
	return result.toString();
}
 
Example 5
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void appendContent(/* @Nullable */ Collection<?> values, String prefix, StringBuilder result, String indentation) {
	if (values != null) {
		Joiner joiner = Joiner.on("\n  " + indentation);
		result.append("\n").append(indentation).append(prefix).append(":\n").append(indentation).append("  ");
		joiner.appendTo(result, values);
	}
}
 
Example 6
Source File: BasicDao.java    From ob1k with Apache License 2.0 5 votes vote down vote up
private String createQueryForIds(final String baseQuery, final String tableName, final String idColumnName,
                                 final List<?> ids) {
  final StringBuilder query = new StringBuilder(baseQuery);
  query.append(' ');
  query.append(withBackticks(tableName));
  query.append(" where ");
  query.append(withBackticks(idColumnName));
  query.append(" in (");
  final Joiner joiner = Joiner.on(',');
  joiner.appendTo(query, transform(ids, BasicDao::withQuote)); // todo: why it's not just List<String> ?
  query.append(");");

  return query.toString();
}
 
Example 7
Source File: BasicDao.java    From ob1k with Apache License 2.0 5 votes vote down vote up
private String createQueryForIds(final String baseQuery, final String tableName, final String idColumnName,
                                 final List<?> ids) {
  final StringBuilder query = new StringBuilder(baseQuery);
  query.append(' ');
  query.append(withBackticks(tableName));
  query.append(" where ");
  query.append(withBackticks(idColumnName));
  query.append(" in (");
  final Joiner joiner = Joiner.on(',');
  joiner.appendTo(query, transform(ids, BasicDao::withQuote)); // todo: why it's not just List<String> ?
  query.append(");");

  return query.toString();
}
 
Example 8
Source File: RequiredProviders.java    From bazel with Apache License 2.0 5 votes vote down vote up
/** Helper method to describe lists of sets of things. */
private static <T> void describe(
    StringBuilder result,
    ImmutableList<ImmutableSet<T>> listOfSets,
    Function<T, String> describeOne) {
  Joiner joiner = Joiner.on(", ");
  for (ImmutableSet<T> ids : listOfSets) {
    if (result.length() > 0) {
      result.append(" or ");
    }
    result.append((ids.size() > 1) ? "[" : "");
    joiner.appendTo(result, ids.stream().map(describeOne).iterator());
    result.append((ids.size() > 1) ? "]" : "");
  }
}
 
Example 9
Source File: AbstractFlowspecNlriParser.java    From bgpcep with Eclipse Public License 1.0 4 votes vote down vote up
protected final String stringNlri(final List<Flowspec> flows) {
    final StringBuilder buffer = new StringBuilder("all packets ");
    final Joiner joiner = Joiner.on(FLOW_SEPARATOR);
    joiner.appendTo(buffer, flows.stream().map(this::encodeFlow).collect(Collectors.toList()));
    return buffer.toString().replace("  ", " ");
}
 
Example 10
Source File: BasicDao.java    From ob1k with Apache License 2.0 4 votes vote down vote up
private <T> String createSaveCommand(final List<T> entries, final String tableName, final EntityMapper<T> mapper) {
  // using the following syntax: INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

  if (entries == null || entries.isEmpty())
    throw new IllegalArgumentException("entries must contain at least on entry");

  final StringBuilder command = new StringBuilder("insert into ");
  command.append(withBackticks(tableName));

  // setting the columns part (col1, col2, ...)
  command.append(" (");
  final T first = entries.get(0);
  final List<String> columnNames = new ArrayList<>(mapper.map(first).keySet());
  final Joiner joiner = Joiner.on(',');
  joiner.appendTo(command, transform(columnNames, BasicDao::withBackticks));
  command.append(") ");

  command.append(" values ");

  // setting the values part values (val11, val12, ...), (val21, val22, ...), ...
  for (final T entry : entries) {
    if (entry != first)
      command.append(",");

    command.append(" (");
    final List<String> values = new ArrayList<>();
    final Map<String, Object> elements = mapper.map(entry);
    for (final String column : columnNames) {
      final Object value = elements.get(column);
      if (value != null) {
        final String queryValue = withQuote(value);
        values.add(queryValue);
      } else {
        values.add("NULL");
      }
    }

    joiner.appendTo(command, values);
    command.append(") ");
  }

  command.append(";");
  return command.toString();
}
 
Example 11
Source File: BasicDao.java    From ob1k with Apache License 2.0 4 votes vote down vote up
private <T> String createSaveCommand(final List<T> entries, final String tableName, final EntityMapper<T> mapper) {
  // using the following syntax: INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

  if (entries == null || entries.isEmpty())
    throw new IllegalArgumentException("entries must contain at least on entry");

  final StringBuilder command = new StringBuilder("insert into ");
  command.append(withBackticks(tableName));

  // setting the columns part (col1, col2, ...)
  command.append(" (");
  final T first = entries.get(0);
  final List<String> columnNames = new ArrayList<>(mapper.map(first).keySet());
  final Joiner joiner = Joiner.on(',');
  joiner.appendTo(command, transform(columnNames, BasicDao::withBackticks));
  command.append(") ");

  command.append(" values ");

  // setting the values part values (val11, val12, ...), (val21, val22, ...), ...
  for (final T entry : entries) {
    if (entry != first)
      command.append(",");

    command.append(" (");
    final List<String> values = new ArrayList<>();
    final Map<String, Object> elements = mapper.map(entry);
    for (final String column : columnNames) {
      final Object value = elements.get(column);
      if (value != null) {
        final String queryValue = withQuote(value);
        values.add(queryValue);
      } else {
        values.add("NULL");
      }
    }

    joiner.appendTo(command, values);
    command.append(") ");
  }

  command.append(";");
  return command.toString();
}
 
Example 12
Source File: ShellEscaper.java    From bazel with Apache License 2.0 2 votes vote down vote up
/**
 * Escapes all strings in {@code argv} individually and joins them into {@code out} using the
 * specified {@link Joiner}. The result is appended directly into {@code out}, without adding a
 * separator.
 *
 * <p>The resulting strings are the same as if escaped one by one using {@link
 * #escapeString(String)}.
 *
 * <p>Example: if the joiner is {@code Joiner.on('|')}, then the input {@code ["abc", "de'f"]}
 * will be escaped as "{@code abc|'de'\''f'}". If {@code out} initially contains "{@code 123}",
 * then the returned {@code Appendable} will contain "{@code 123abc|'de'\''f'}".
 *
 * @param out what the result will be appended to
 * @param argv the strings to escape and join
 * @param joiner the {@link Joiner} to use to join the escaped strings
 * @return the same reference as {@code out}, now containing the joined, escaped fragments
 * @throws IOException if an I/O error occurs while appending
 */
public static Appendable escapeJoinAll(
    Appendable out, Iterable<? extends String> argv, Joiner joiner) throws IOException {
  return joiner.appendTo(out, escapeAll(argv));
}