Subversion Repositories eFlore/Applications.coel

Rev

Rev 1321 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client.util;

import java.util.ArrayList;
import java.util.Date;

import com.google.gwt.i18n.client.DateTimeFormat;

public class UtilString {
        
        /**
         *  Mets la première lettre d'une chaine en majuscule
         *  
         *  @param chaineDeCaractere
         *  @result ChaineDeCaractere
         */
        public static String ucFirst(String inputStr)   {
                if (isEmpty(inputStr))  {
                        return "";
                }
                return inputStr.substring(0,1).toUpperCase() + inputStr.substring(1, inputStr.length());
        }
        
        public static boolean isEmpty(String chaine)    {
                boolean etreVide = false;
                if (chaine == null || chaine.equals("") || chaine.equals("0000-00-00") || chaine.equals("0000-00-00 00:00:00")) {
                        etreVide = true;
                }
                return etreVide;
        }
        
        public static double formaterEnDouble(String nombre)    {
                if (!isEmpty(nombre)) {
                        return Double.parseDouble(nombre);
                }
                return new Double(0);
        }
        
        public static int formaterEnEntier(String nombre)       {
                if (!isEmpty(nombre)) {
                        return Integer.parseInt(nombre);
                }
                return new Integer(0);
        }
        
        public static Date formaterEnDate(String dateChaine)    {
                Date date = null;
                if (!isEmpty(dateChaine)) {
                        if (dateChaine.matches("^[0-9]{4}-00-00$")) {
                                dateChaine = dateChaine.replaceFirst("^([0-9]{4})-00-00$", "$1-01-01");
                        } else if (dateChaine.matches("^[0-9]{4}-[0-9]{2}-00$")) {
                                dateChaine = dateChaine.replaceFirst("^([0-9]{4})-([0-9]{2})-00$", "$1-$2-01");
                        }
                        date = UtilDate.formatDateMysql.parseStrict(dateChaine);
                }
                return date;
        }
        
        public static boolean isEmpty(ArrayList<String> entree) {
                return !(entree!=null && !entree.toString().equals("[]"));
        }
}