use of com.google.gson.internal.LinkedTreeMap in project bitsquare by bitsquare.
the class PoloniexProvider method request.
public Map<String, PriceData> request() throws IOException, HttpException {
Map<String, PriceData> marketPriceMap = new HashMap<>();
String response = httpClient.requestWithGET("?command=returnTicker", "User-Agent", "");
LinkedTreeMap<String, Object> treeMap = new Gson().fromJson(response, LinkedTreeMap.class);
treeMap.entrySet().stream().forEach(e -> {
Object value = e.getValue();
String invertedCurrencyPair = e.getKey();
String altcoinCurrency = null;
if (invertedCurrencyPair.startsWith("BTC")) {
String[] tokens = invertedCurrencyPair.split("_");
if (tokens.length == 2) {
altcoinCurrency = tokens[1];
if (supportedAltcoins.contains(altcoinCurrency)) {
if (value instanceof LinkedTreeMap) {
LinkedTreeMap<String, Object> data = (LinkedTreeMap) value;
marketPriceMap.put(altcoinCurrency, new PriceData(altcoinCurrency, parseDouble((String) data.get("lowestAsk")), parseDouble((String) data.get("highestBid")), parseDouble((String) data.get("last"))));
}
}
} else {
log.error("invertedCurrencyPair has invalid format: invertedCurrencyPair=" + invertedCurrencyPair);
}
}
});
return marketPriceMap;
}
use of com.google.gson.internal.LinkedTreeMap in project bitsquare by bitsquare.
the class CoinmarketcapProvider method request.
public Map<String, PriceData> request() throws IOException, HttpException {
Map<String, PriceData> marketPriceMap = new HashMap<>();
String response = httpClient.requestWithGET("v1/ticker/?limit=200", "User-Agent", "");
List<LinkedTreeMap<String, Object>> list = new Gson().fromJson(response, ArrayList.class);
list.stream().forEach(treeMap -> {
String code = (String) treeMap.get("symbol");
if (supportedAltcoins.contains(code)) {
double price_btc = parseDouble((String) treeMap.get("price_btc"));
marketPriceMap.put(code, new PriceData(code, price_btc, price_btc, price_btc));
}
});
return marketPriceMap;
}
use of com.google.gson.internal.LinkedTreeMap in project bitsquare by bitsquare.
the class PriceProvider method getAll.
public Tuple2<Map<String, Long>, Map<String, MarketPrice>> getAll() throws IOException, HttpException {
Map<String, MarketPrice> marketPriceMap = new HashMap<>();
String json = httpClient.requestWithGET("all", "User-Agent", "Bitsquare/" + Version.VERSION + ", uid:" + uid);
LinkedTreeMap<String, Object> map = new Gson().fromJson(json, LinkedTreeMap.class);
Map<String, Long> tsMap = new HashMap<>();
tsMap.put("btcAverageTs", ((Double) map.get("btcAverageTs")).longValue());
tsMap.put("poloniexTs", ((Double) map.get("poloniexTs")).longValue());
tsMap.put("coinmarketcapTs", ((Double) map.get("coinmarketcapTs")).longValue());
List<LinkedTreeMap<String, Object>> list = (ArrayList<LinkedTreeMap<String, Object>>) map.get("data");
list.stream().forEach(treeMap -> {
marketPriceMap.put((String) treeMap.get("c"), new MarketPrice((String) treeMap.get("c"), (double) treeMap.get("a"), (double) treeMap.get("b"), (double) treeMap.get("l")));
});
return new Tuple2<>(tsMap, marketPriceMap);
}
use of com.google.gson.internal.LinkedTreeMap in project instructure-android by instructure.
the class QuizMultipleDropdownBinder method setPreviouslySelectedAnswer.
private static void setPreviouslySelectedAnswer(QuizSubmissionQuestion quizSubmissionQuestion, String answer, Spinner spinner, ArrayList<QuizSubmissionAnswer> list) {
if (quizSubmissionQuestion.getAnswer() != null) {
// set the one they selected last time
for (String map : ((LinkedTreeMap<String, String>) quizSubmissionQuestion.getAnswer()).keySet()) {
if (!answer.equals("null") && map.equals(answer)) {
String matchId = ((LinkedTreeMap<String, String>) quizSubmissionQuestion.getAnswer()).get(map);
// now see if we have a match in the list of matches
int listIndex = 0;
for (QuizSubmissionAnswer match : list) {
if (Long.toString(match.getId()).equals(matchId)) {
spinner.setSelection(listIndex);
break;
}
listIndex++;
}
}
}
}
}
use of com.google.gson.internal.LinkedTreeMap in project instructure-android by instructure.
the class QuizMatchingBinder method setPreviouslySelectedAnswer.
private static void setPreviouslySelectedAnswer(QuizSubmissionQuestion quizSubmissionQuestion, QuizSubmissionAnswer answer, Spinner spinner, ArrayList<QuizSubmissionMatch> list) {
if (quizSubmissionQuestion.getAnswer() != null) {
// the api returns an ArrayList of LinkedTreeMaps
for (LinkedTreeMap<String, String> map : ((ArrayList<LinkedTreeMap<String, String>>) quizSubmissionQuestion.getAnswer())) {
int answerId = Integer.parseInt(map.get(Const.QUIZ_ANSWER_ID));
if (answerId == answer.getId()) {
if (map.get(Const.QUIZ_MATCH_ID) != null && !map.get(Const.QUIZ_MATCH_ID).equals("null")) {
int matchId = Integer.parseInt(map.get(Const.QUIZ_MATCH_ID));
// now see if we have a match in the list of matches
int listIndex = 0;
for (QuizSubmissionMatch match : list) {
if (match.getId() == matchId) {
spinner.setSelection(listIndex);
break;
}
listIndex++;
}
}
}
}
}
}
Aggregations