All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.deephaven.engine.util.IterableUtils Maven / Gradle / Ivy

There is a newer version: 0.37.1
Show newest version
/**
 * Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
 */
package io.deephaven.engine.util;

import java.util.function.Function;

public class IterableUtils {
    public static  String makeCommaSeparatedList(Iterable s) {
        return appendCommaSeparatedList(new StringBuilder(), s).toString();
    }

    public static  String makeSeparatedList(Iterable s, String separator, Function renderer) {
        return appendSeparatedList(new StringBuilder(), s, separator, renderer).toString();
    }

    public static  StringBuilder appendCommaSeparatedList(StringBuilder sb, Iterable s) {
        return appendSeparatedList(sb, s, ", ", Object::toString);
    }

    public static  StringBuilder appendSeparatedList(StringBuilder sb, Iterable s, String separator,
            Function renderer) {
        String currentSep = "";
        for (T element : s) {
            sb.append(currentSep);
            sb.append(renderer.apply(element));
            currentSep = separator;
        }
        return sb;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy