Refine search
@Override public String toString() { return "{" + Joiner.on(", ").withKeyValueSeparator(":").join(map) + "}"; }
public void testMap() { MapJoiner j = Joiner.on(';').withKeyValueSeparator(':'); assertEquals("", j.join(ImmutableMap.of())); assertEquals(":", j.join(ImmutableMap.of("", ""))); Map<String, String> mapWithNulls = Maps.newLinkedHashMap(); mapWithNulls.put("a", null); mapWithNulls.put(null, "b"); try { j.join(mapWithNulls); fail(); } catch (NullPointerException expected) { } assertEquals("a:00;00:b", j.useForNull("00").join(mapWithNulls)); StringBuilder sb = new StringBuilder(); j.appendTo(sb, ImmutableMap.of(1, 2, 3, 4, 5, 6)); assertEquals("1:2;3:4;5:6", sb.toString()); }
/** * Returns a map joiner with the same behavior as this one, except automatically substituting * {@code nullText} for any provided null keys or values. */ public MapJoiner useForNull(String nullText) { return new MapJoiner(joiner.useForNull(nullText), keyValueSeparator); } }
@Override public Map<String, String> apply(UserMetadata md) { Builder<String, String> headers = ImmutableMap.builder(); if (md.getMetadata().size() > 0) { String header = Joiner.on(',').withKeyValueSeparator("=").join(md.getMetadata()); headers.put("x-emc-meta", header); } if (md.getListableMetadata().size() > 0) { String header = Joiner.on(',').withKeyValueSeparator("=").join(md.getListableMetadata()); headers.put("x-emc-listable-meta", header); } if (md.getTags().size() > 0) { String header = Joiner.on(',').join(md.getTags()); headers.put("x-emc-tags", header); } if (md.getListableTags().size() > 0) { String header = Joiner.on(',').join(md.getListableTags()); headers.put("x-emc-listable-tags", header); } return headers.build(); } }
@Override public String apply(Map<String, String> partitionDMLInfo) { if (partitionDMLInfo == null) { return StringUtils.EMPTY; } return String.format(" PARTITION (%s)", Joiner.on(",").withKeyValueSeparator("=").join(Maps.transformValues(partitionDMLInfo, QUOTE_PARTITION_VALUES))); } };
out.println(Json.asPrettyStringUnchecked(sortedJobIds)); } else { final Map<JobId, Job> filteredJobs = Maps.newHashMap(); for (final Entry<JobId, Job> entry : jobs.entrySet()) { if (jobStatuses.containsKey(entry.getKey())) { final String command = on(' ').join(escape(job.getCommand())); final String env = Joiner.on(" ").withKeyValueSeparator("=").join(job.getEnv()); final JobStatus status = jobStatuses.get(jobId); table.row(full ? jobId : jobId.toShortString(), jobId.getName(), jobId.getVersion(),
@Override public String toString() { return Objects.toStringHelper(this) .add("startTs", startTs) .add("endTs", endTs) .add("resolution", resolution) .add("metrics", metrics) .add("sliceByTags", Joiner.on(",").withKeyValueSeparator(":").useForNull("null").join(sliceByTagValues)) .add("groupByTags", Joiner.on(",").join(groupByTags)).toString(); } }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("source: ").append(getField(FIELD_SOURCE)).append(" | "); final String message = getField(FIELD_MESSAGE).toString().replaceAll("\\n", "").replaceAll("\\t", ""); sb.append("message: "); if (message.length() > 225) { sb.append(message.substring(0, 225)).append(" (...)"); } else { sb.append(message); } sb.append(" { "); final Map<String, Object> filteredFields = Maps.newHashMap(fields); filteredFields.remove(FIELD_SOURCE); filteredFields.remove(FIELD_MESSAGE); Joiner.on(" | ").withKeyValueSeparator(": ").appendTo(sb, filteredFields); sb.append(" }"); return sb.toString(); }
private void recalculateClusterAddresses(Map<Entity, String> nodes) { Map<String,String> addresses = Maps.newHashMap(); for (Entity entity : nodes.keySet()) { if (entity instanceof EtcdNode) { EtcdNode node = (EtcdNode) entity; addresses.put(node.getNodeName(), getNodeAddress(node)); } } sensors().set(ETCD_CLUSTER_NODES, ImmutableMap.copyOf(nodes)); sensors().set(NODE_LIST, Joiner.on(",").withKeyValueSeparator("=").join(addresses)); }
@SuppressWarnings("unchecked") final Map<String, Object> map = (Map<String, Object>) value; final Map<String, Object> withoutNull = Maps.filterEntries(map, REMOVE_NULL_PREDICATE); if (flatten) { final Joiner.MapJoiner joiner = Joiner.on(listSeparator).withKeyValueSeparator(kvSeparator); return Collections.singleton(Entry.create(processedKey, joiner.join(withoutNull))); } else { final List<Entry> result = new ArrayList<>(map.size()); final Joiner joiner = Joiner.on(listSeparator).skipNulls(); return Collections.singleton(Entry.create(processedKey, joiner.join(values))); } else if (value == null) {
TableDescription(String tableName, ImmutableMap<String, String> columnDefintions, String selectColumns) { this.tableName = tableName; this.dropCommand = "DROP TABLE " + tableName; this.createCommand = "CREATE TABLE " + tableName + " ( " + Joiner.on(", ").withKeyValueSeparator(" ").join(columnDefintions) + " )"; this.insertCommand = "INSERT INTO " + tableName + " (" + Joiner.on(", ").join(columnDefintions.keySet()) + ") VALUES ("; this.selectCommand = "SELECT " + selectColumns + " FROM " + tableName; }
String assembleLongPollRefreshUrl(String uri, String appId, String cluster, String dataCenter, Map<String, Long> notificationsMap) { Map<String, String> queryParams = Maps.newHashMap(); queryParams.put("appId", queryParamEscaper.escape(appId)); queryParams.put("cluster", queryParamEscaper.escape(cluster)); queryParams .put("notifications", queryParamEscaper.escape(assembleNotifications(notificationsMap))); if (!Strings.isNullOrEmpty(dataCenter)) { queryParams.put("dataCenter", queryParamEscaper.escape(dataCenter)); } String localIp = m_configUtil.getLocalIp(); if (!Strings.isNullOrEmpty(localIp)) { queryParams.put("ip", queryParamEscaper.escape(localIp)); } String params = MAP_JOINER.join(queryParams); if (!uri.endsWith("/")) { uri += "/"; } return uri + "notifications/v2?" + params; }
@Override public String toString() { StringBuilder builder = new StringBuilder("@").append(annotationType.getQualifiedName()); if (!namedValues.isEmpty()) { builder .append('(') .append(Joiner.on(", ").withKeyValueSeparator(" = ").join(namedValues)) .append(')'); } return builder.toString(); }
public void testEntries() { MapJoiner j = Joiner.on(";").withKeyValueSeparator(":"); assertEquals("", j.join(ImmutableMultimap.of().entries())); assertEquals("", j.join(ImmutableMultimap.of().entries().iterator())); assertEquals(":", j.join(ImmutableMultimap.of("", "").entries())); assertEquals(":", j.join(ImmutableMultimap.of("", "").entries().iterator())); assertEquals("1:a;1:b", j.join(ImmutableMultimap.of("1", "a", "1", "b").entries())); assertEquals("1:a;1:b", j.join(ImmutableMultimap.of("1", "a", "1", "b").entries().iterator())); Map<String, String> mapWithNulls = Maps.newLinkedHashMap(); mapWithNulls.put("a", null); mapWithNulls.put(null, "b"); j.join(entriesWithNulls); fail(); } catch (NullPointerException expected) { j.join(entriesWithNulls.iterator()); fail(); } catch (NullPointerException expected) { assertEquals("a:00;00:b", j.useForNull("00").join(entriesWithNulls)); assertEquals("a:00;00:b", j.useForNull("00").join(entriesWithNulls.iterator())); j.appendTo(sb1, ImmutableMultimap.of(1, 2, 3, 4, 5, 6, 1, 3, 5, 10).entries()); assertEquals("1:2;1:3;3:4;5:6;5:10", sb1.toString()); j.appendTo(sb2, ImmutableMultimap.of(1, 2, 3, 4, 5, 6, 1, 3, 5, 10).entries().iterator()); assertEquals("1:2;1:3;3:4;5:6;5:10", sb2.toString());
private String interpolateCode(String simpleName, Collection<String> attributeNames) { // The implementation is pretty dumb, sorry: no regex, parsing or fancy libraries String c = info.code; if (c.isEmpty()) { return "(" + ATTR_JOINER.join(literals) + ")"; } if (c.contains(P_ALL)) { c = c.replace(P_ALL, ATTR_JOINER.join(literals)); } c = c.replace(P_SIMPLE_NAME, simpleName); if (c.contains(P_ALL_NAMES)) { String literals = FluentIterable.from(attributeNames) .transform(ToLiteral.FUNCTION) .join(COMMA_JOINER); c = c.replace(P_ALL_NAMES, "{" + literals + "}"); } for (Entry<String, String> e : literals.entrySet()) { c = c.replace(P_L + e.getKey() + P_R, e.getValue()); } return c; }
/** Implements {@link Annotation#toString}. */ private static String annotationToString( Class<? extends Annotation> type, Map<String, Object> members) throws Exception { StringBuilder sb = new StringBuilder().append("@").append(type.getName()).append("("); JOINER.appendTo(sb, Maps.transformValues(members, DEEP_TO_STRING_FN)); return sb.append(")").toString(); }
/** * Returns a {@code MapJoiner} using the given key-value separator, and the same configuration as * this {@code Joiner} otherwise. */ public MapJoiner withKeyValueSeparator(String keyValueSeparator) { return new MapJoiner(this, keyValueSeparator); }
/** * Appends the string representation of each entry of {@code map}, using the previously * configured separator and key-value separator, to {@code appendable}. */ @CanIgnoreReturnValue public <A extends Appendable> A appendTo(A appendable, Map<?, ?> map) throws IOException { return appendTo(appendable, map.entrySet()); }