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

org.sdmxsource.util.StringUtil Maven / Gradle / Ivy

package org.sdmxsource.util;

import java.lang.ref.WeakReference;
import java.util.WeakHashMap;

/**
 * The type String util.
 */
public class StringUtil {
    private static final WeakHashMap> s_manualCache = new WeakHashMap>(100000);

    /**
     * Manual intern string.
     *
     * @param str the str
     * @return the string
     */
    public static String manualIntern(String str) {
        if (str == null) {
            return str;
        }
        final WeakReference cached = s_manualCache.get(str);
        if (cached != null) {
            final String value = cached.get();
            if (value != null)
                return value;
        }
        str = new String(str);
        s_manualCache.put(str, new WeakReference(str));
        return str;
    }

    /**
     * Trim leading whitespace string.
     *
     * @param s the s
     * @return the string
     */
    public static String trimLeadingWhitespace(final String s) {
        if (s == null || s.isEmpty()) {
            return s;
        }
        for (int i = 0, len = s.length(); i < len; i++) {
            if (!Character.isWhitespace(s.charAt(i))) {
                return s.substring(i);
            }
        }
        return "";
    }

    /**
     * Has text boolean.
     *
     * @param s the s
     * @return the boolean
     */
    public static boolean hasText(final String s) {
        if (s == null || s.isEmpty()) {
            return false;
        }
        for (int i = 0, len = s.length(); i < len; i++) {
            if (!Character.isWhitespace(s.charAt(i))) {
                return true;
            }
        }
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy