Subversion Repositories eFlore/Applications.coel

Rev

Rev 1415 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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