Subversion Repositories eFlore/Applications.coel

Rev

Rev 1383 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
619 gduche 1
package org.tela_botanica.client.util;
2
 
1321 gduche 3
import java.util.ArrayList;
954 jpm 4
import java.util.Date;
5
 
6
import com.google.gwt.i18n.client.DateTimeFormat;
7
 
619 gduche 8
public class UtilString {
9
 
10
	/**
11
	 *  Mets la première lettre d'une chaine en majuscule
12
	 *
13
	 *  @param chaineDeCaractere
14
	 *  @result ChaineDeCaractere
15
	 */
16
	public static String ucFirst(String inputStr)	{
798 gduche 17
		if (isEmpty(inputStr))	{
674 gduche 18
			return "";
19
		}
619 gduche 20
		return inputStr.substring(0,1).toUpperCase() + inputStr.substring(1, inputStr.length());
21
	}
798 gduche 22
 
965 jpm 23
	public static boolean isEmpty(String chaine)	{
24
		boolean etreVide = false;
25
		if (chaine == null || chaine.equals("") || chaine.equals("0000-00-00") || chaine.equals("0000-00-00 00:00:00")) {
26
			etreVide = true;
27
		}
28
		return etreVide;
798 gduche 29
	}
948 jpm 30
 
31
	public static double formaterEnDouble(String nombre)	{
32
		if (!isEmpty(nombre)) {
33
			return Double.parseDouble(nombre);
34
		}
35
		return new Double(0);
36
	}
949 jpm 37
 
38
	public static int formaterEnEntier(String nombre)	{
39
		if (!isEmpty(nombre)) {
40
			return Integer.parseInt(nombre);
41
		}
42
		return new Integer(0);
43
	}
954 jpm 44
 
45
	public static Date formaterEnDate(String dateChaine)	{
46
		Date date = null;
975 jpm 47
		if (!isEmpty(dateChaine)) {
48
			if (dateChaine.matches("^[0-9]{4}-00-00$")) {
49
				dateChaine = dateChaine.replaceFirst("^([0-9]{4})-00-00$", "$1-01-01");
50
			} else if (dateChaine.matches("^[0-9]{4}-[0-9]{2}-00$")) {
51
				dateChaine = dateChaine.replaceFirst("^([0-9]{4})-([0-9]{2})-00$", "$1-$2-01");
52
			}
53
			date = UtilDate.formatDateMysql.parseStrict(dateChaine);
954 jpm 54
		}
55
		return date;
56
	}
1321 gduche 57
 
58
	public static boolean isEmpty(ArrayList<String> entree)	{
59
		return !(entree!=null && !entree.toString().equals("[]"));
60
	}
1439 cyprien 61
 
62
	public static boolean isNumber(String str, boolean emptyIsTrue) {
63
		if (emptyIsTrue) return (str.matches("[0-9]*"));
64
		else return (str.matches("[0-9]+"));
65
	}
619 gduche 66
}