Subversion Repositories eFlore/Applications.del

Compare Revisions

Ignore whitespace Rev 1885 → Rev 1886

/trunk/src/org/tela_botanica/del/client/utils/UtilitairesAutoCompletionService.java
1,13 → 1,15
package org.tela_botanica.del.client.utils;
 
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
 
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.Response;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Window;
 
public class UtilitairesAutoCompletionService {
31,30 → 33,42
return chaineTraitee;
}
public static Map<String, String> extraireTaxonsNumNomsResultatRetourSimple(Response response) {
public static Map<String, InfosNomPourAutocompletion> extraireTaxonsNumNomsResultatRetourSimple(Response response) {
JSONObject responseValue = JSONParser.parseStrict(response.getText()).isObject();
JSONArray noms = responseValue.get("resultats").isArray();
final int taillemax = noms.size();
Map<String, String> retourTaxons = new HashMap<String, String>(taillemax);
// LinkedHashMap préserve l'ordre
Map<String, InfosNomPourAutocompletion> retourTaxons = new LinkedHashMap<String, InfosNomPourAutocompletion>(taillemax);
for (int i = 0; i < taillemax; i++) {
String nom = (noms.get(i).isArray().get(0).isString().stringValue());
String taxon = (noms.get(i).isArray().get(1).isString().stringValue());
retourTaxons.put(nom, taxon);
// comment rendre compliqué un format fait pour être simple
JSONObject obj = noms.get(i).isObject();
String ns = obj.get("ns").isString().stringValue();
double nn = obj.get("nn").isNumber().doubleValue();
boolean retenu = obj.get("retenu").isBoolean().booleanValue();
// empile, Gérard !
retourTaxons.put(ns, new InfosNomPourAutocompletion(nn, ns, retenu));
}
return retourTaxons;
}
public static String[] parserResultatRetourSimple(Response response) {
public static InfosNomPourAutocompletion[] parserResultatRetourSimple(Response response) {
JSONObject responseValue = JSONParser.parseStrict(response.getText()).isObject();
JSONArray noms = responseValue.get("resultats").isArray();
String[] valeurs = new String[0];
 
final int taillemax = noms.size();
valeurs = new String[taillemax];
InfosNomPourAutocompletion[] valeurs = new InfosNomPourAutocompletion[taillemax];
 
// Eh les gars, si on refaisait le même truc ici que celui qu'on vient de faire en haut ?
for (int i = 0; i < taillemax; i++) {
valeurs[i] = (noms.get(i).isArray().get(0).isString().stringValue());
// comment rendre comp... euh j'ai déjà dit ça il y a 20 lignes, non ?
JSONObject obj = noms.get(i).isObject();
String ns = obj.get("ns").isString().stringValue();
double nn = obj.get("nn").isNumber().doubleValue();
boolean retenu = obj.get("retenu").isBoolean().booleanValue();
// empile, Marcel !
valeurs[i] = new InfosNomPourAutocompletion(nn, ns, retenu);
}
return valeurs;
}