Subversion Repositories eFlore/Applications.del

Rev

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

package org.tela_botanica.del.client.utils;

import com.google.gwt.i18n.client.NumberFormat;

public class StringUtils {
        
        public static boolean checkStringNotNull(String s){
                if(s!=null&&!s.equals("")){
                        return true;
                }
                return false;
        }
        
        public static String normaliser(String mot) {
                
                mot = mot.toLowerCase().trim().replace(" ", "");
                
                // Le manque de support des librairies standard java
                // nous oblige à utiliser cette méthode un peu batarde
                char[] accents = {'à','á','â','ã','ä','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ù','ú','û','ü','ý','ÿ','À','Á','Â','Ã','Ä','Ç','È','É','Ê','Ë', 'Ì','Í','Î','Ï','Ñ','Ò','Ó','Ô','Õ','Ö','Ù','Ú','Û','Ü','Ý'};
                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'};
        
                for (int i = 0; i < accents.length; i++) {
                        mot = mot.replace(accents[i], sansAccents[i]);
                }
        
                return mot;
        }
        
        public static native void logChaine(String s) /*-{
                if(!!($wnd.console && $wnd.console.log)) {
                        $wnd.console.log(s);
                }
        }-*/;
        
        public static String formaterNombre(double valeur, int decimales) {
            StringBuilder patternNb = new StringBuilder(
                    (decimales <= 0) ? "" : ".");
            for (int i = 0; i < decimales; i++) {
                patternNb.append('0');
            }
            
            if(valeur == 0) {
                patternNb.insert(0, 0);
            }
            
            return NumberFormat.getFormat(patternNb.toString()).format(valeur);
        }
}