Subversion Repositories eFlore/Applications.coel

Rev

Rev 1468 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1468 Rev 1918
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
	
-
 
23
	public static String mettrePremiereLettreEnMajuscule(String str) {
-
 
24
		return str.substring(0, 1).toUpperCase() + str.substring(1);
-
 
25
	}
22
	
26
	
23
	public static boolean isEmpty(String chaine)	{
27
	public static boolean isEmpty(String chaine)	{
24
		boolean etreVide = false;
28
		boolean etreVide = false;
25
		if (chaine == null || chaine.equals("") || chaine.equals("0000-00-00") || chaine.equals("0000-00-00 00:00:00")) {
29
		if (chaine == null || chaine.equals("") || chaine.equals("0000-00-00") || chaine.equals("0000-00-00 00:00:00")) {
26
			etreVide = true;
30
			etreVide = true;
27
		}
31
		}
28
		return etreVide;
32
		return etreVide;
29
	}
33
	}
30
	
34
	
31
	public static double formaterEnDouble(String nombre)	{
35
	public static double formaterEnDouble(String nombre)	{
32
		if (!isEmpty(nombre)) {
36
		if (!isEmpty(nombre)) {
33
			return Double.parseDouble(nombre);
37
			return Double.parseDouble(nombre);
34
		}
38
		}
35
		return new Double(0);
39
		return new Double(0);
36
	}
40
	}
37
	
41
	
38
	public static int formaterEnEntier(String nombre)	{
42
	public static int formaterEnEntier(String nombre)	{
39
		if (!isEmpty(nombre)) {
43
		if (!isEmpty(nombre)) {
40
			return Integer.parseInt(nombre);
44
			return Integer.parseInt(nombre);
41
		}
45
		}
42
		return new Integer(0);
46
		return new Integer(0);
43
	}
47
	}
44
	
48
	
45
	public static Date formaterEnDate(String dateChaine)	{
49
	public static Date formaterEnDate(String dateChaine)	{
46
		Date date = null;
50
		Date date = null;
47
		if (!isEmpty(dateChaine)) {
51
		if (!isEmpty(dateChaine)) {
48
			if (dateChaine.matches("^[0-9]{4}-00-00$")) {
52
			if (dateChaine.matches("^[0-9]{4}-00-00$")) {
49
				dateChaine = dateChaine.replaceFirst("^([0-9]{4})-00-00$", "$1-01-01");
53
				dateChaine = dateChaine.replaceFirst("^([0-9]{4})-00-00$", "$1-01-01");
50
			} else if (dateChaine.matches("^[0-9]{4}-[0-9]{2}-00$")) {
54
			} 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");
55
				dateChaine = dateChaine.replaceFirst("^([0-9]{4})-([0-9]{2})-00$", "$1-$2-01");
52
			}
56
			}
53
			date = UtilDate.formatDateMysql.parseStrict(dateChaine);
57
			date = UtilDate.formatDateMysql.parseStrict(dateChaine);
54
		}
58
		}
55
		return date;
59
		return date;
56
	}
60
	}
57
	
61
	
58
	public static boolean isEmpty(ArrayList<String> entree)	{
62
	public static boolean isEmpty(ArrayList<String> entree)	{
59
		return !(entree!=null && !entree.toString().equals("[]"));
63
		return !(entree!=null && !entree.toString().equals("[]"));
60
	}
64
	}
61
	
65
	
62
	public static boolean isNumber(String str, boolean emptyIsTrue) {
66
	public static boolean isNumber(String str, boolean emptyIsTrue) {
63
		if (emptyIsTrue) return (str.matches("[0-9]*"));
67
		if (emptyIsTrue) return (str.matches("[0-9]*"));
64
		else return (str.matches("[0-9]+"));
68
		else return (str.matches("[0-9]+"));
65
	}
69
	}
66
}
70
}