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

dev.marksman.collectionviews.Util Maven / Gradle / Ivy

There is a newer version: 1.2.3
Show newest version
package dev.marksman.collectionviews;

final class Util {

    private Util() {

    }

    static String iterableToString(String prefix, Iterable iterable) {
        StringBuilder output = new StringBuilder();
        output.append(prefix);
        output.append('(');
        renderElements(output, iterable);
        output.append(')');
        return output.toString();
    }

    static boolean isPrimitive(Object obj) {
        return (obj instanceof Primitive);
    }

    private static void renderElements(StringBuilder output, Iterable iterable) {
        boolean inner = false;
        for (Object elem : iterable) {
            if (inner) {
                output.append(", ");
            }
            renderElement(output, elem);
            inner = true;
        }
    }

    private static void renderElement(StringBuilder output, Object elem) {
        if (elem == null) {
            output.append("null");
        } else {
            output.append(elem.toString());
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy