/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */

package net.ranides.assira.text;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public final class StringTraits {
    
    private StringTraits() {
        /* utility class */
    }
    
    public static boolean isEmpty(CharSequence value) {
		return null == value || 0 == value.length();
	}
	
	public static boolean isBlank(CharSequence value) {
		return isEmpty(value) || value.toString().trim().isEmpty();
	}
	
    public static boolean isNumber(CharSequence text) {
        if(isEmpty(text)) {
            return false;
        }
        for(int i=0,n=text.length(); i<n; i++) {
            if(!isNumber(text.charAt(i))) {
                return false;
            }
        }
        return true;
    }
    
    private static boolean isNumber(char c) {
        return c>='0' && c<='9';
    }
    
    public static boolean starts(String text, String prefix) {
		return null != text && text.startsWith(prefix);
	}
    
    public static boolean ends(String text, String suffix) {
		return null != text && text.endsWith(suffix);
	}
    
    public static boolean contains(String text, int ch) {
        return null != text && -1 != text.indexOf(ch);
    }
    
    public static boolean contains(String text, String fragment) {
		return null != text && text.contains(fragment);
	}
    
}
