Subversion Repositories eFlore/Applications.del

Rev

Rev 1517 | Rev 1953 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1062 benjamin 1
package org.tela_botanica.del.client.utils;
2
 
1833 aurelien 3
import com.google.gwt.i18n.client.NumberFormat;
4
 
1062 benjamin 5
public class StringUtils {
6
 
7
	public static boolean checkStringNotNull(String s){
8
		if(s!=null&&!s.equals("")){
9
			return true;
10
		}
11
		return false;
12
	}
1165 aurelien 13
 
14
	public static String normaliser(String mot) {
15
 
16
		mot = mot.toLowerCase().trim().replace(" ", "");
17
 
18
		// Le manque de support des librairies standard java
19
		// nous oblige à utiliser cette méthode un peu batarde
20
		char[] accents = {'à','á','â','ã','ä','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ù','ú','û','ü','ý','ÿ','À','Á','Â','Ã','Ä','Ç','È','É','Ê','Ë', 'Ì','Í','Î','Ï','Ñ','Ò','Ó','Ô','Õ','Ö','Ù','Ú','Û','Ü','Ý'};
21
		char[] sansAccents = {'a','a','a','a','a','c', 'e','e','e','e','i','i','i','i','n','o','o','o','o','o','u','u','u','u', 'y','y','A','A','A','A','A','C','E','E','E','E','I','I','I','I','N','O','O','O','O','O','U','U','U','U','Y'};
22
 
23
		for (int i = 0; i < accents.length; i++) {
24
			mot = mot.replace(accents[i], sansAccents[i]);
25
		}
26
 
27
		return mot;
28
	}
1517 aurelien 29
 
30
	public static native void logChaine(String s) /*-{
31
		if(!!($wnd.console && $wnd.console.log)) {
32
			$wnd.console.log(s);
33
		}
34
	}-*/;
1833 aurelien 35
 
36
	public static String formaterNombre(double valeur, int decimales) {
37
	    StringBuilder patternNb = new StringBuilder(
38
	            (decimales <= 0) ? "" : ".");
39
	    for (int i = 0; i < decimales; i++) {
40
	    	patternNb.append('0');
41
	    }
42
 
43
	    if(valeur == 0) {
44
	    	patternNb.insert(0, 0);
45
	    }
46
 
47
	    return NumberFormat.getFormat(patternNb.toString()).format(valeur);
48
	}
1062 benjamin 49
}