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