protected static String toString(List<ServerAddress> addresses) { return Strings.join(ADDRESS_DELIMITER, addresses); }
/** * Returns a new String composed of the supplied values joined together with a copy of the specified {@code delimiter}. * All {@code null} values are simply ignored. * * @param delimiter the delimiter that separates each element * @param values the values to join together. * @return a new {@code String} that is composed of the {@code elements} separated by the {@code delimiter} * * @throws NullPointerException If {@code delimiter} or {@code elements} is {@code null} * @see java.lang.String#join */ public static <T> String join(CharSequence delimiter, Iterable<T> values) { return join(delimiter, values, v -> { return v != null ? v.toString() : null; }); }
/** * Get the string containing the host names for the replica sets. The result is a string with each replica set hosts * separated by a semicolon. * * @return the host names; never null * @see #parse(String) */ public String hosts() { return Strings.join(";", all()); }
protected String extractEnumAndSetOptionsAsString(Column column) { return Strings.join(",", extractEnumAndSetOptions(column)); }
/** * Obtain a configuration instance by copying the supplied map of string keys and object values. The entries within the map * are copied so that the resulting Configuration cannot be modified. * * @param properties the properties; may be null or empty * @return the configuration; never null */ public static Configuration from(Map<String, ?> properties) { return from(properties, value -> { if (value == null) return null; if (value instanceof Collection<?>) { return Strings.join(",", (List<?>) value); } return value.toString(); }); }
public EnumRecommender(Class<T> enumType) { // Not all enums support EnumeratedValue yet if (Arrays.asList(enumType.getInterfaces()).contains(EnumeratedValue.class)) { this.literals = Arrays.stream(enumType.getEnumConstants()) .map(x -> ((EnumeratedValue)x).getValue()) .map(String::toLowerCase) .collect(Collectors.toSet()); } else { this.literals = Arrays.stream(enumType.getEnumConstants()) .map(Enum::name) .map(String::toLowerCase) .collect(Collectors.toSet()); } this.validValues = Collections.unmodifiableList(new ArrayList<>(this.literals)); this.literalsStr = Strings.join(", ", validValues); }
numThreads, collections.size(), Strings.join(", ", collections)); for (int i = 0; i != numThreads; ++i) { copyThreads.submit(() -> {
@Test public void joinShouldExcludeAllNullableElements() { assertThat(Strings.join(",", Arrays.asList(null, null, null))).isEqualTo(""); }
if (rsStatus != null) { String addressStr = Strings.join(",", client.getServerAddressList()); String replicaSetName = rsStatus.getName(); replicaSetSpecs.add(new ReplicaSet(addressStr, replicaSetName, null));
@Test public void joinShouldExcludeSecondNullableElement() { assertThat(Strings.join(",", Arrays.asList("a", null, "c"))).isEqualTo("a,c"); }
@Test public void joinWithConversionShouldConvertAllElements() { assertThat(Strings.join(",", Arrays.asList("a", "b", "c"), s -> "_" + s)).isEqualTo("_a,_b,_c"); }
@Test public void joinShouldExcludeFirstNullableElement() { assertThat(Strings.join(",", Arrays.asList(null, "b", "c"))).isEqualTo("b,c"); }
/** * Consume and return the next token that must match one of the supplied values. * * @param typeOptions the options for the type of the current token * @return the token that was consumed and that matches one of the supplied options * @throws ParsingException if the current token doesn't match the supplied value * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public String consumeAnyOf(int... typeOptions) throws IllegalStateException { if (completed) { throw new ParsingException(tokens.get(tokens.size() - 1).position(), "No more content but was expecting one token of type " + Strings.join("|", typeOptions)); } for (int typeOption : typeOptions) { if (typeOption == ANY_TYPE || matches(typeOption)) return consume(); } // Failed to find a match ... String found = currentToken().value(); Position pos = currentToken().position(); String fragment = generateFragment(); String msg = "Expecting " + Strings.join("|", typeOptions) + " at line " + pos.line() + ", column " + pos.column() + " but found '" + found + "': " + fragment; throw new ParsingException(pos, msg); }
protected void assertParseEnumAndSetOptions(String typeExpression, String optionString) { List<String> options = MySqlDdlParser.parseSetAndEnumOptions(typeExpression); String commaSeperatedOptions = Strings.join(",", options); assertThat(optionString).isEqualTo(commaSeperatedOptions); }
@Override protected void assertParseEnumAndSetOptions(String typeExpression, String optionString) { List<String> options = MySqlAntlrDdlParser.parseSetAndEnumOptions(typeExpression); String commaSeperatedOptions = Strings.join(",", options); assertThat(optionString).isEqualTo(commaSeperatedOptions); }
/** * Returns a new String composed of the supplied values joined together with a copy of the specified {@code delimiter}. * All {@code null} values are simply ignored. * * @param delimiter the delimiter that separates each element * @param values the values to join together. * @return a new {@code String} that is composed of the {@code elements} separated by the {@code delimiter} * * @throws NullPointerException If {@code delimiter} or {@code elements} is {@code null} * @see java.lang.String#join */ public static <T> String join(CharSequence delimiter, Iterable<T> values) { return join(delimiter, values, v -> { return v != null ? v.toString() : null; }); }
/** * Obtain a configuration instance by copying the supplied map of string keys and object values. The entries within the map * are copied so that the resulting Configuration cannot be modified. * * @param properties the properties; may be null or empty * @return the configuration; never null */ public static Configuration from(Map<String, ?> properties) { return from(properties, value -> { if (value == null) return null; if (value instanceof Collection<?>) { return Strings.join(",", (List<?>) value); } return value.toString(); }); }
public EnumRecommender(Class<T> enumType) { // Not all enums support EnumeratedValue yet if (Arrays.asList(enumType.getInterfaces()).contains(EnumeratedValue.class)) { this.literals = Arrays.stream(enumType.getEnumConstants()) .map(x -> ((EnumeratedValue)x).getValue()) .map(String::toLowerCase) .collect(Collectors.toSet()); } else { this.literals = Arrays.stream(enumType.getEnumConstants()) .map(Enum::name) .map(String::toLowerCase) .collect(Collectors.toSet()); } this.validValues = Collections.unmodifiableList(new ArrayList<>(this.literals)); this.literalsStr = Strings.join(", ", validValues); }
@Override protected void assertParseEnumAndSetOptions(String typeExpression, String optionString) { List<String> options = MySqlAntlrDdlParser.parseSetAndEnumOptions(typeExpression); String commaSeperatedOptions = Strings.join(",", options); assertThat(optionString).isEqualTo(commaSeperatedOptions); }
protected void assertParseEnumAndSetOptions(String typeExpression, String optionString) { List<String> options = MySqlDdlParser.parseSetAndEnumOptions(typeExpression); String commaSeperatedOptions = Strings.join(",", options); assertThat(optionString).isEqualTo(commaSeperatedOptions); }