Search in sources :

Example 1 with LinkedTreeMap

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;
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) HashMap(java.util.HashMap) PriceData(io.bitsquare.pricefeed.PriceData) Gson(com.google.gson.Gson)

Example 2 with LinkedTreeMap

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;
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) PriceData(io.bitsquare.pricefeed.PriceData) Gson(com.google.gson.Gson)

Example 3 with LinkedTreeMap

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);
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) Gson(com.google.gson.Gson) Tuple2(io.bitsquare.common.util.Tuple2)

Example 4 with LinkedTreeMap

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++;
                }
            }
        }
    }
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) QuizSubmissionAnswer(com.instructure.canvasapi2.models.QuizSubmissionAnswer)

Example 5 with LinkedTreeMap

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++;
                    }
                }
            }
        }
    }
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) QuizSubmissionMatch(com.instructure.canvasapi2.models.QuizSubmissionMatch)

Aggregations

LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)30 Gson (com.google.gson.Gson)15 ArrayList (java.util.ArrayList)10 JsonObject (com.google.gson.JsonObject)6 HashMap (java.util.HashMap)6 InputStreamReader (java.io.InputStreamReader)5 URL (java.net.URL)5 List (java.util.List)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)3 LSCustomErrorStrategy (org.ballerinalang.langserver.common.LSCustomErrorStrategy)3 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)3 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)3 MarketoRecordResult (org.talend.components.marketo.runtime.client.type.MarketoRecordResult)3 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)3 NonNull (android.support.annotation.NonNull)2 Tuple2 (bisq.common.util.Tuple2)2 JsonElement (com.google.gson.JsonElement)2 StatusCallback (com.instructure.canvasapi2.StatusCallback)2