public static String join(List<String> list, String separator) { StringBuilder sb = new StringBuilder(); for (String ele : list) { if (sb.length() > 0) { sb.append(separator); } sb.append(ele); } return sb.toString(); }
/** * Returns a string containing the string representation of each of {@code parts}, using the * previously configured separator between each. * * @since 11.0 */ public final String join(Iterator<?> parts) { return appendTo(new StringBuilder(), parts).toString(); }
@Override public boolean canDecode(CharSequence chars) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < chars.length(); i++) { char c = chars.charAt(i); if (separator.indexOf(c) < 0) { builder.append(c); } } return delegate.canDecode(builder); }
static <T> StringBuilder allSequenceFrequency(Map<Integer, List<T>> its) { StringBuilder b = new StringBuilder(); for (Map.Entry<Integer, List<T>> e : its.entrySet()) { if (b.length() > 0) { b.append(", "); } b.append(e.getKey()).append("={"); b.append(sequenceFrequency(e.getValue())); b.append("}"); } return b; } static <T> StringBuilder sequenceFrequency(Iterable<T> it) {
private void appendStackTrace(StringBuilder b, Throwable ex, String prefix) { b.append(prefix).append(ex).append('\n'); for (StackTraceElement stackElement : ex.getStackTrace()) { b.append("\t\tat ").append(stackElement).append('\n'); } if (ex.getCause() != null) { b.append("\tCaused by: "); appendStackTrace(b, ex.getCause(), ""); } }
@Override public StringBuilder call() { return new StringBuilder(); } },
static void checkSchedulerBadMethod(String baseClassName) throws Exception { File f = MaybeNo2Dot0Since.findSource(baseClassName); if (f == null) { return; } StringBuilder b = readFile(f); StringBuilder e = new StringBuilder(); scanForBadMethod(b, "@SchedulerSupport", "Scheduler:", e, baseClassName); if (e.length() != 0) { System.out.println(e); fail(e.toString()); } }
/** * Reads all characters from a {@link Readable} object into a {@link String}. Does not close the * {@code Readable}. * * @param r the object to read from * @return a string containing all the characters * @throws IOException if an I/O error occurs */ public static String toString(Readable r) throws IOException { return toStringBuilder(r).toString(); }
public void testCharactersOfIsView() { StringBuilder builder = new StringBuilder("abc"); List<Character> chars = Lists.charactersOf(builder); assertEquals(asList('a', 'b', 'c'), chars); builder.append("def"); assertEquals(asList('a', 'b', 'c', 'd', 'e', 'f'), chars); builder.deleteCharAt(5); assertEquals(asList('a', 'b', 'c', 'd', 'e'), chars); }
public void removeTrailingSlash() { int index = this.path.length() - 1; if (this.path.charAt(index) == '/') { this.path.deleteCharAt(index); } }
/** * Subclasses must call this method after finishing character processing, in order to ensure that * any unterminated line in the buffer is passed to {@link #handleLine}. * * @throws IOException if an I/O error occurs */ protected void finish() throws IOException { if (sawReturn || line.length() > 0) { finishLine(false); } }
/** * Returns a string containing the string representation of each entry in {@code entries}, using * the previously configured separator and key-value separator. * * @since 11.0 */ @Beta public String join(Iterator<? extends Entry<?, ?>> entries) { return appendTo(new StringBuilder(), entries).toString(); }
@Override int decodeTo(byte[] target, CharSequence chars) throws DecodingException { StringBuilder stripped = new StringBuilder(chars.length()); for (int i = 0; i < chars.length(); i++) { char c = chars.charAt(i); if (separator.indexOf(c) < 0) { stripped.append(c); } } return delegate.decodeTo(target, stripped); }
static <T> StringBuilder allSequenceFrequency(Map<Integer, List<T>> its) { StringBuilder b = new StringBuilder(); for (Map.Entry<Integer, List<T>> e : its.entrySet()) { if (b.length() > 0) { b.append(", "); } b.append(e.getKey()).append("={"); b.append(sequenceFrequency(e.getValue())); b.append("}"); } return b; } static <T> StringBuilder sequenceFrequency(Iterable<T> it) {
static void namesAndValuesToQueryString(StringBuilder out, List<String> namesAndValues) { for (int i = 0, size = namesAndValues.size(); i < size; i += 2) { String name = namesAndValues.get(i); String value = namesAndValues.get(i + 1); if (i > 0) out.append('&'); out.append(name); if (value != null) { out.append('='); out.append(value); } } }
@Override public StringBuilder call() { return new StringBuilder(); } },