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

io.infinicast.StringExtensions Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package io.infinicast;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class StringExtensions {
    public static boolean IsNullOrEmpty(String rhs) {
        if (null == rhs) return true;
        return rhs.isEmpty();
    }

    public static String butLast(String rhs) {
        return rhs.substring(0, rhs.length() - 1);
    }

    public static List splitAsPath(String rhs) {
        ArrayList result = new ArrayList<>();
        for (String s : rhs.split("/"))
            result.add(s);
        return result;
    }

    public static String removeFrom(String rhs, int index) {
        return rhs.substring(0, index);
    }

    public static boolean areEqual(String lhs, String rhs) {
        if (null == lhs) return null == rhs;
        if (null == rhs) return null == lhs;
        return lhs.equals(rhs);
    }

    public static String formatException(Exception rhs) {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(buffer);
        rhs.printStackTrace(ps);
        return rhs.getMessage() + "\r\n" + new String(buffer.toByteArray(), StandardCharsets.UTF_8);
    }
}







© 2015 - 2024 Weber Informatics LLC | Privacy Policy