Subversion Repositories eFlore/Applications.cel

Rev

Rev 2276 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2276 Rev 2392
Line 1... Line 1...
1
package org.tela_botanica.client.util;
1
package org.tela_botanica.client.util;
Line -... Line 2...
-
 
2
 
-
 
3
import java.util.ArrayList;
-
 
4
import java.util.Collections;
2
 
5
import java.util.Comparator;
3
import java.util.HashMap;
6
import java.util.HashMap;
4
import java.util.Iterator;
7
import java.util.List;
-
 
8
import java.util.Map;
Line 5... Line 9...
5
import java.util.Map;
9
import java.util.Vector;
6
 
10
 
Line 7... Line -...
7
import org.tela_botanica.client.modeles.objets.ChampEtendu;
-
 
8
import org.tela_botanica.client.modeles.objets.Observation;
11
import org.tela_botanica.client.modeles.objets.ChampEtendu;
9
 
12
import org.tela_botanica.client.modeles.objets.Observation;
10
import com.google.gwt.http.client.URL;
13
 
Line 11... Line 14...
11
import com.google.gwt.json.client.JSONArray;
14
import com.google.gwt.json.client.JSONArray;
Line 26... Line 29...
26
		if(jo.get(index) != null && jo.get(index).isArray() != null) {	
29
		if(jo.get(index) != null && jo.get(index).isArray() != null) {	
27
			JSONArray tabJo = jo.get(index).isArray();
30
			JSONArray tabJo = jo.get(index).isArray();
28
			for (int i = 0; i < tabJo.size(); i++) {
31
			for (int i = 0; i < tabJo.size(); i++) {
29
				JSONObject champJson = tabJo.get(i).isObject();
32
				JSONObject champJson = tabJo.get(i).isObject();
30
				String cle = champJson.get("cle").isString().stringValue();
33
				String cle = champJson.get("cle").isString().stringValue();
31
				String label = champJson.get("label").isString().stringValue();
34
				String label = cle;
32
				String valeur = champJson.get("valeur").isString().stringValue();
35
				String valeur = champJson.get("valeur").isString().stringValue();
33
				ChampEtendu champ = new ChampEtendu(cle, label, valeur);
36
				ChampEtendu champ = new ChampEtendu(cle, label, valeur);
34
				mapValeurs.put(cle, champ);
37
				mapValeurs.put(cle, champ);
35
			}
38
			}
Line 317... Line 320...
317
	}
320
	}
Line 318... Line 321...
318
 
321
 
319
	public static String tronquerNombrePourAffichage(String nombre, int decimales) {
322
	public static String tronquerNombrePourAffichage(String nombre, int decimales) {
320
		return tronquerNombrePourAffichage(nombre, decimales, '.');
323
		return tronquerNombrePourAffichage(nombre, decimales, '.');
-
 
324
	}
-
 
325
	
-
 
326
	// Adapté de http://www.programcreek.com/2011/03/java-method-for-spliting-a-camelcase-string/
-
 
327
	public static String formaterCleChampsEtenduPourAffichage(String s) {
-
 
328
		char[] cArray = s.toCharArray();
-
 
329
		 
-
 
330
		Vector<Integer> al = new Vector<Integer>();
-
 
331
		al.add(0);
-
 
332
	 
-
 
333
		// get all upper case letter index positions
-
 
334
		for (int i = 1; i < cArray.length; i++) {
-
 
335
			char c = cArray[i];
-
 
336
			//add more interested index beyond upper case letter
-
 
337
			if (c >= 65 && c <= 90) {
-
 
338
				al.add(i);
-
 
339
			}
-
 
340
		}
-
 
341
	 
-
 
342
		Vector<String> strl = new Vector<String>();
-
 
343
	 
-
 
344
		// this handles the all lower letter case
-
 
345
		if (al.size() == 1) {
-
 
346
			strl.add(s);
-
 
347
			return depilerChaineListee(strl, " ");
-
 
348
		}
-
 
349
	 
-
 
350
	 
-
 
351
		int prev = 0;
-
 
352
		int curr = 0;
-
 
353
		int begin = 0;
-
 
354
		for (int k = 1; k < al.size(); k++) {
-
 
355
	 
-
 
356
			curr = al.get(k);
-
 
357
	 
-
 
358
			if(curr == s.length() - 1){
-
 
359
	 
-
 
360
			}
-
 
361
	 
-
 
362
			if (curr == prev + 1 && curr != s.length() - 1) {
-
 
363
				prev = curr;
-
 
364
			} else if(curr == prev + 1 &&  curr == s.length() - 1){
-
 
365
				strl.add(s.substring(begin, curr+1));
-
 
366
			}else {
-
 
367
	 
-
 
368
				strl.add(s.substring(prev, curr));
-
 
369
				prev = curr;
-
 
370
				begin = curr;
-
 
371
				if (k == al.size() - 1) {
-
 
372
					strl.add(s.substring(curr, s.length()));
-
 
373
				}
-
 
374
			}
-
 
375
		}
-
 
376
	 
-
 
377
		return depilerChaineListee(strl, " ");
-
 
378
	}
-
 
379
	
-
 
380
	private static String depilerChaineListee(Vector<String> strl, String separateur) {
-
 
381
		String s = "";
-
 
382
		for(int i = 0; i < strl.size(); i++) {
-
 
383
			s += strl.get(i);
-
 
384
			if(i != strl.size() - 1) {
-
 
385
				s += separateur;
-
 
386
			}
-
 
387
		}
-
 
388
		return s;
-
 
389
	}
-
 
390
	
-
 
391
	public static Map<String, ChampEtendu> trierListeChampsEtendus(Map<String, ChampEtendu> listeChampsEtendus) {
-
 
392
		List<String> tmp = new ArrayList<String>(listeChampsEtendus.keySet());
-
 
393
		Collections.sort(tmp, new Comparator<String>() {
-
 
394
			 
-
 
395
		    @Override
-
 
396
		    public int compare(String arg0, String arg1) {
-
 
397
		        return arg0.compareTo(arg1);
-
 
398
		    }
-
 
399
		 
-
 
400
		});
-
 
401
		return listeChampsEtendus;
321
	}
402
	}