001package uk.ac.ebi.pride.jmztab2.model;
002
003import static uk.ac.ebi.pride.jmztab2.model.MZTabConstants.*;
004
005/**
006 * Provide a couple of functions for translate, parse and print formatted string defined in the mzTab specification.
007 *
008 * @author qingwei
009 * @since 30/01/13
010 * 
011 */
012public final class MZTabStringUtils {
013
014    /**
015     * Private constructor.
016     */
017    private MZTabStringUtils() {}
018    
019    /**
020     * Check the string is null or blank.
021     *
022     * @param s a {@link java.lang.String} object.
023     * @return a boolean.
024     */
025    public static boolean isEmpty(String s) {
026        return s == null || s.trim().length() == 0;
027    }
028
029    /**
030     * Translate the string to the first char is upper case, others are lower case.
031     *
032     * @param s a {@link java.lang.String} object.
033     * @return a {@link java.lang.String} object.
034     */
035    public static String toCapital(String s) {
036        if (isEmpty(s)) {
037            return s;
038        }
039
040        if (s.length() == 1) {
041            return s.toUpperCase();
042        }
043
044        String firstChar = s.substring(0, 1);
045        String leftString = s.substring(1);
046        return firstChar.toUpperCase().concat(leftString.toLowerCase());
047    }
048
049    /**
050     * Pre-process the String object. If object is null, return null; otherwise
051     * remove heading and tailing white space.
052     *
053     * @param target a {@link java.lang.String} object.
054     * @return a {@link java.lang.String} object.
055     */
056    public static String parseString(String target) {
057        if (target == null || target.isEmpty() || target.trim().equalsIgnoreCase(NULL)) {
058            return null;
059        } else {
060            return target.trim();
061        }
062    }
063
064}