Search in sources :

Example 16 with LinkedTreeMap

use of com.google.gson.internal.LinkedTreeMap in project instructure-android by instructure.

the class QuizSubmissionQuestionListRecyclerAdapter method addMatchingQuestion.

private void addMatchingQuestion(final QuizSubmissionQuestion baseItem, QuizMatchingViewHolder holder, int position, int courseColor) {
    addAnsweredQuestion(baseItem);
    QuizMatchingBinder.bind(holder, baseItem, courseColor, position, shouldLetAnswer, getContext(), embeddedWebViewCallback, webViewClientCallback, new QuizPostMatching() {

        @Override
        public void postMatching(final long questionId, HashMap<Long, Integer> answers) {
            QuizManager.postQuizQuestionMatching(quizSubmission, questionId, answers, true, new StatusCallback<QuizSubmissionQuestionResponse>() {

                @Override
                public void onResponse(@NonNull Response<QuizSubmissionQuestionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                    if (type == ApiType.CACHE)
                        return;
                    final QuizSubmissionQuestionResponse quizSubmissionQuestionResponse = response.body();
                    if (quizSubmissionQuestionResponse.getQuizSubmissionQuestions() != null) {
                        for (QuizSubmissionQuestion question : quizSubmissionQuestionResponse.getQuizSubmissionQuestions()) {
                            if (baseItem.getId() == question.getId()) {
                                baseItem.setAnswer(question.getAnswer());
                            }
                        }
                        // make sure each answer has a match
                        int numAnswers = 0;
                        // API returns an ArrayList of LinkedTreeMaps
                        for (LinkedTreeMap<String, String> map : ((ArrayList<LinkedTreeMap<String, String>>) baseItem.getAnswer())) {
                            if (map.get(Const.QUIZ_MATCH_ID) != null && !map.get(Const.QUIZ_MATCH_ID).equals("null")) {
                                numAnswers++;
                            }
                        }
                        if (numAnswers == baseItem.getAnswers().length) {
                            addAnsweredQuestion(questionId);
                        } else {
                            removeAnsweredQuestion(questionId);
                        }
                    }
                }
            });
        }
    }, flagStateCallback);
}
Also used : QuizPostMatching(com.instructure.candroid.interfaces.QuizPostMatching) LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) StatusCallback(com.instructure.canvasapi2.StatusCallback) QuizSubmissionQuestion(com.instructure.canvasapi2.models.QuizSubmissionQuestion) QuizSubmissionResponse(com.instructure.canvasapi2.models.QuizSubmissionResponse) Response(retrofit2.Response) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse) NonNull(android.support.annotation.NonNull) ApiType(com.instructure.canvasapi2.utils.ApiType) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)

Example 17 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.getMatchId() == matchId) {
                            spinner.setSelection(listIndex);
                            break;
                        }
                        listIndex++;
                    }
                }
            }
        }
    }
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) QuizSubmissionMatch(com.instructure.canvasapi2.models.QuizSubmissionMatch)

Example 18 with LinkedTreeMap

use of com.google.gson.internal.LinkedTreeMap in project toolkit by googleapis.

the class DiscoGapicProvider method generate.

public Map<String, Doc> generate(String snippetFileName) {
    Map<String, Doc> docs = new LinkedTreeMap<>();
    for (DocumentToViewTransformer transformer : transformers) {
        List<ViewModel> surfaceDocs = transformer.transform(model, productConfig);
        for (ViewModel surfaceDoc : surfaceDocs) {
            if (snippetFileName != null && !surfaceDoc.templateFileName().equals(snippetFileName)) {
                continue;
            }
            Doc doc = snippetSetRunner.generate(surfaceDoc);
            if (doc == null) {
                // generation failed; failures are captured in the model.
                continue;
            }
            docs.put(surfaceDoc.outputPath(), doc);
        }
    }
    return docs;
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) Doc(com.google.api.tools.framework.snippet.Doc) ViewModel(com.google.api.codegen.viewmodel.ViewModel) DocumentToViewTransformer(com.google.api.codegen.discogapic.transformer.DocumentToViewTransformer)

Example 19 with LinkedTreeMap

use of com.google.gson.internal.LinkedTreeMap in project OsmAnd-tools by osmandapp.

the class CoinSenderMain method convertPaymentsToMap.

public static Map<String, Double> convertPaymentsToMap(List<LinkedTreeMap> paymentsList, double MIN_PAY) {
    Map<String, Double> payments = new LinkedHashMap<>();
    for (LinkedTreeMap map : paymentsList) {
        Double btc = (Double) map.get("btc");
        String address = TransactionAnalyzer.simplifyBTC((String) map.get("btcaddress"));
        if (address == null) {
            continue;
        }
        if (payments.containsKey(address)) {
            payments.put(address, btc + payments.get(address));
        } else {
            payments.put(address, btc);
        }
    }
    double skip = 0;
    int cnt = 0;
    for (String addr : new ArrayList<>(payments.keySet())) {
        if (payments.get(addr) < MIN_PAY) {
            skip += payments.remove(addr);
            cnt++;
        }
    }
    System.out.println("Skipped " + cnt + " payments ( tx  < minimal = " + MIN_PAY + ") in total " + skip * 1000 + " mBTC");
    return payments;
}
Also used : LinkedTreeMap(com.google.gson.internal.LinkedTreeMap)

Example 20 with LinkedTreeMap

use of com.google.gson.internal.LinkedTreeMap in project webdrivermanager by bonigarcia.

the class WebDriverManager method getDriversFromGitHub.

protected List<URL> getDriversFromGitHub() throws IOException {
    List<URL> urls;
    URL driverUrl = config().getDriverUrl(driverUrlKey);
    String driverNameString = listToString(getDriverName());
    log.info("Reading {} to seek {}", driverUrl, driverNameString);
    if (isUsingTaobaoMirror()) {
        urls = getDriversFromMirror(driverUrl);
    } else {
        String driverVersion = versionToDownload;
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(openGitHubConnection(driverUrl)))) {
            GsonBuilder gsonBuilder = new GsonBuilder();
            Gson gson = gsonBuilder.create();
            GitHubApi[] releaseArray = gson.fromJson(reader, GitHubApi[].class);
            if (driverVersion != null) {
                releaseArray = new GitHubApi[] { getVersion(releaseArray, driverVersion) };
            }
            urls = new ArrayList<>();
            for (GitHubApi release : releaseArray) {
                if (release != null) {
                    List<LinkedTreeMap<String, Object>> assets = release.getAssets();
                    for (LinkedTreeMap<String, Object> asset : assets) {
                        urls.add(new URL(asset.get("browser_download_url").toString()));
                    }
                }
            }
        }
    }
    return urls;
}
Also used : InputStreamReader(java.io.InputStreamReader) LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Config.listToString(io.github.bonigarcia.wdm.Config.listToString) URL(java.net.URL) BufferedReader(java.io.BufferedReader)

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