/*******************************************************************************
* Copyright (c) 2011 Michel DAVID mimah35-at-gmail.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package fr.gotorennes.remote;
import android.content.Context;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import fr.gotorennes.domain.MetroStation;
public class MetroStationOrderService extends RemoteService<MetroStation> {
private static MetroStationOrderService instance;
private MetroStationOrderService(Context context) {
super();
}
public static synchronized MetroStationOrderService getInstance(Context context) {
if (instance == null) {
instance = new MetroStationOrderService(context);
}
return instance;
}
private Map<String,Integer> cache = null;
public Integer getMetroStationOrder(String name) {
if (cache == null || cache.isEmpty()) {
cache = new HashMap<String, Integer>();
List<MetroStation> stations = loadList("refine.libellecourtparcours=JFK");
for (MetroStation station : stations) {
cache.put(station.name, station.sequence);
}
}
Integer order = cache.get(name);
return order != null ? order : 0;
}
@Override
protected MetroStation populate(JSONObject jsonObject) throws JSONException {
MetroStation station = new MetroStation();
station.name = jsonObject.getString("nomarret");
station.sequence = jsonObject.getInt("ordre");
return station;
}
@Override
protected String getDataSet() {
return "tco-metro-topologie-dessertes-td";
}
}