Example usage for org.json JSONObject getInt

List of usage examples for org.json JSONObject getInt

Introduction

In this page you can find the example usage for org.json JSONObject getInt.

Prototype

public int getInt(String key) throws JSONException 

Source Link

Document

Get the int value associated with a key.

Usage

From source file:com.hichinaschool.flashcards.libanki.Sched.java

private int _deckRevLimitSingle(JSONObject d) {
    try {/*from   ww  w .  j  a  va2 s.co m*/
        if (d.getInt("dyn") != 0) {
            return mReportLimit;
        }
        JSONObject c = mCol.getDecks().confForDid(d.getLong("id"));
        return Math.max(0, c.getJSONObject("rev").getInt("perDay") - d.getJSONArray("revToday").getInt(1));
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.hichinaschool.flashcards.libanki.Sched.java

private int _nextLapseIvl(Card card, JSONObject conf) {
    try {/* ww  w .j  a  va2s . com*/
        return Math.max(conf.getInt("minInt"), (int) (card.getIvl() * conf.getDouble("mult")));
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.hichinaschool.flashcards.libanki.Sched.java

/**
 * Ideal next interval for CARD, given EASE.
 *///from w  w  w  .  ja  v  a 2  s  .c  om
private int _nextRevIvl(Card card, int ease) {
    try {
        long delay = _daysLate(card);
        int interval = 0;
        JSONObject conf = _revConf(card);
        double fct = card.getFactor() / 1000.0;
        int ivl2 = _constrainedIvl((int) ((card.getIvl() + delay / 4) * 1.2), conf, card.getIvl());
        int ivl3 = _constrainedIvl((int) ((card.getIvl() + delay / 2) * fct), conf, ivl2);
        int ivl4 = _constrainedIvl((int) ((card.getIvl() + delay) * fct * conf.getDouble("ease4")), conf, ivl3);
        if (ease == 2) {
            interval = ivl2;
        } else if (ease == 3) {
            interval = ivl3;
        } else if (ease == 4) {
            interval = ivl4;
        }
        // interval capped?
        return Math.min(interval, conf.getInt("maxIvl"));
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.hichinaschool.flashcards.libanki.Sched.java

public List<Long> rebuildDyn(long did) {
    if (did == 0) {
        did = mCol.getDecks().selected();
    }//from ww  w . j ava2  s. co m
    JSONObject deck = mCol.getDecks().get(did);
    try {
        if (deck.getInt("dyn") == 0) {
            Log.e(AnkiDroidApp.TAG, "error: deck is not a filtered deck");
            return null;
        }
    } catch (JSONException e1) {
        throw new RuntimeException(e1);
    }
    // move any existing cards back first, then fill
    emptyDyn(did);
    List<Long> ids = _fillDyn(deck);
    if (ids.isEmpty()) {
        return null;
    }
    // and change to our new deck
    mCol.getDecks().select(did);
    return ids;
}

From source file:com.hichinaschool.flashcards.libanki.Sched.java

private int _dynIvlBoost(Card card) {
    if (card.getODid() == 0 || card.getType() != 2 || card.getFactor() == 0) {
        Log.e(AnkiDroidApp.TAG, "error: deck is not a filtered deck");
        return 0;
    }//from  w w w  . j a  v  a  2  s  . c  o m
    long elapsed = card.getIvl() - (card.getODue() - mToday);
    double factor = ((card.getFactor() / 1000.0) + 1.2) / 2.0;
    int ivl = Math.max(1, Math.max(card.getIvl(), (int) (elapsed * factor)));
    JSONObject conf = _revConf(card);
    try {
        return Math.min(conf.getInt("maxIvl"), ivl);
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.hichinaschool.flashcards.libanki.Sched.java

/** Leech handler. True if card was a leech. */
private boolean _checkLeech(Card card, JSONObject conf) {
    int lf;// w  ww . j a v a 2 s  .c  om
    try {
        lf = conf.getInt("leechFails");
        if (lf == 0) {
            return false;
        }
        // if over threshold or every half threshold reps after that
        if (card.getLapses() >= lf && (card.getLapses() - lf) % Math.max(lf / 2, 1) == 0) {
            // add a leech tag
            Note n = card.note();
            n.addTag("leech");
            n.flush();
            // handle
            if (conf.getInt("leechAction") == 0) {
                // if it has an old due, remove it from cram/relearning
                if (card.getODue() != 0) {
                    card.setDue(card.getODue());
                }
                if (card.getODid() != 0) {
                    card.setDid(card.getODid());
                }
                card.setODue(0);
                card.setODid(0);
                card.setQueue(-1);
            }
            return true;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    return false;
}

From source file:com.hichinaschool.flashcards.libanki.Sched.java

private boolean _resched(Card card) {
    JSONObject conf = _cardConf(card);
    try {/*from   ww w .j a  v  a 2s.  c  om*/
        if (conf.getInt("dyn") == 0) {
            return true;
        }
        return conf.getBoolean("resched");
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.hichinaschool.flashcards.libanki.Sched.java

public boolean leechActionSuspend(Card card) {
    JSONObject conf;
    try {/*from w w  w.java2 s  .  c om*/
        conf = _cardConf(card).getJSONObject("lapse");
        if (conf.getInt("leechAction") == 0) {
            return true;
        } else {
            return false;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitTagTest.java

@Test
public void testTagFailed() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    IPath[] clonePaths = createTestProjects(workspaceLocation);

    for (IPath clonePath : clonePaths) {
        // clone a  repo
        JSONObject clone = clone(clonePath);
        String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

        // get project/folder metadata
        WebRequest request = getGetRequest(cloneContentLocation);
        WebResponse response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject folder = new JSONObject(response.getText());

        JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT);
        String gitTagUri = gitSection.getString(GitConstants.KEY_TAG);
        String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

        // tag HEAD with 'tag'
        JSONObject tag = tag(gitTagUri, "tag", Constants.HEAD);
        assertEquals("tag", tag.getString(ProtocolConstants.KEY_NAME));
        new URI(tag.getString(ProtocolConstants.KEY_LOCATION));

        // tag HEAD with 'tag' again (TagHandler) - should fail
        request = getPostGitTagRequest(gitTagUri, "tag", Constants.HEAD);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, response.getResponseCode());

        // tag HEAD with 'tag' again (CommitHandler) - should fail
        request = getPutGitCommitRequest(gitHeadUri, "tag");
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, response.getResponseCode());

        // modify
        JSONObject testTxt = getChild(folder, "test.txt");
        modifyFile(testTxt, "test.txt change");

        // add//w w  w .j  a  v  a 2s.  co  m
        JSONObject folder1 = getChild(folder, "folder");
        JSONObject folderTxt = getChild(folder1, "folder.txt");
        addFile(folderTxt);

        // commit
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // tag next commit with 'tag' again (TagHandler) - should fail
        request = getPostGitTagRequest(gitTagUri, "tag", Constants.HEAD);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, response.getResponseCode());
        JSONObject result = new JSONObject(response.getText());
        assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, result.getInt("HttpCode"));
        assertEquals("Error", result.getString("Severity"));
        assertEquals("An error occured when tagging.", result.getString("Message"));
        assertTrue(result.toString(), result.getString("DetailedMessage").endsWith("already exists"));

        // tag HEAD with 'tag' again (CommitHandler) - should fail
        request = getPutGitCommitRequest(gitHeadUri, "tag");
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, response.getResponseCode());
        result = new JSONObject(response.getText());
        assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, result.getInt("HttpCode"));
        assertEquals("Error", result.getString("Severity"));
        assertEquals("An error occured when tagging.", result.getString("Message"));
        assertTrue(result.toString(), result.getString("DetailedMessage").endsWith("already exists"));
    }
}

From source file:com.BreakingBytes.SifterReader.SifterReader.java

private String getFilterSlug() {
    String projDetailURL = new String();
    int issuesPerPage = IssuesActivity.MAX_PER_PAGE;
    JSONArray status = new JSONArray();
    JSONArray priority = new JSONArray();
    int numStatuses;
    int numPriorities;
    boolean[] filterStatus;
    boolean[] filterPriority;
    try {// w  w w .  java 2s.c  om
        JSONObject filters = mSifterHelper.getFiltersFile();
        if (filters.length() == 0)
            return new String();
        issuesPerPage = filters.getInt(IssuesActivity.PER_PAGE);
        status = filters.getJSONArray(IssuesActivity.STATUS);
        priority = filters.getJSONArray(IssuesActivity.PRIORITY);
        numStatuses = status.length();
        numPriorities = priority.length();
        filterStatus = new boolean[numStatuses];
        filterPriority = new boolean[numPriorities];
        for (int i = 0; i < numStatuses; i++)
            filterStatus[i] = status.getBoolean(i);
        for (int i = 0; i < numPriorities; i++)
            filterPriority[i] = priority.getBoolean(i);
    } catch (Exception e) {
        e.printStackTrace();
        mSifterHelper.onException(e.toString());
        return new String();
    }
    projDetailURL = "?" + IssuesActivity.PER_PAGE + "=" + issuesPerPage;
    projDetailURL += "&" + IssuesActivity.GOTO_PAGE + "=1";
    JSONObject statuses = new JSONObject();
    JSONObject priorities = new JSONObject();
    JSONArray statusNames = new JSONArray();
    JSONArray priorityNames = new JSONArray();
    try {
        JSONObject sifterJSONObject = mSifterHelper.getSifterFilters();
        statuses = sifterJSONObject.getJSONObject(IssuesActivity.STATUSES);
        priorities = sifterJSONObject.getJSONObject(IssuesActivity.PRIORITIES);
        statusNames = statuses.names();
        priorityNames = priorities.names();
    } catch (Exception e) {
        e.printStackTrace();
        mSifterHelper.onException(e.toString());
        return new String();
    }
    try {
        String filterSlug = "&s=";
        for (int i = 0; i < numStatuses; i++) {
            if (filterStatus[i])
                filterSlug += String.valueOf(statuses.getInt(statusNames.getString(i))) + "-";
        }
        if (filterSlug.length() > 3) {
            filterSlug = filterSlug.substring(0, filterSlug.length() - 1);
            projDetailURL += filterSlug;
        }
        filterSlug = "&p=";
        for (int i = 0; i < numPriorities; i++) {
            if (filterPriority[i])
                filterSlug += String.valueOf(priorities.getInt(priorityNames.getString(i))) + "-";
        }
        if (filterSlug.length() > 3) {
            filterSlug = filterSlug.substring(0, filterSlug.length() - 1);
            projDetailURL += filterSlug;
        }
    } catch (JSONException e) {
        e.printStackTrace();
        mSifterHelper.onException(e.toString());
        return new String();
    }
    return projDetailURL;
}