Search in sources :

Example 31 with JSONArray

use of net.sf.json.JSONArray in project compiler by boalang.

the class GetGithubRepoLanguagesMulti method getLanguages.

private static ArrayList<GithubLanguage> getLanguages(String content) {
    ArrayList<GithubLanguage> languages = new ArrayList<GithubLanguage>();
    JSONArray repos = null;
    try {
        repos = (JSONArray) JSONSerializer.toJSON(content);
    } catch (JSONException e) {
    }
    if (repos == null) {
        System.err.println("Error parsing file\n" + content);
        return languages;
    }
    int status = 0, s = 0;
    String name = null, count;
    for (int i = 0; i < content.length(); i++) {
        if (status == 0 && content.charAt(i) == '\"') {
            status = 1;
            s = i + 1;
        } else if (status == 1 && content.charAt(i) == '\"') {
            status = 2;
            name = content.substring(s, i);
        } else if (status == 2 && content.charAt(i) == ':') {
            status = 3;
            s = i + 1;
        } else if (status == 3 && !Character.isDigit(content.charAt(i))) {
            status = 0;
            count = content.substring(s, i);
            languages.add(new GithubLanguage(name, count));
        }
    }
    return languages;
}
Also used : ArrayList(java.util.ArrayList) JSONArray(net.sf.json.JSONArray) JSONException(net.sf.json.JSONException)

Aggregations

JSONArray (net.sf.json.JSONArray)31 JSONObject (net.sf.json.JSONObject)19 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)5 CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)4 Test (org.junit.Test)4 CommandStatus (com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus)3 ProcessorStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus)3 SimpleChartData (com.sohu.cache.web.chart.model.SimpleChartData)3 ParameterDefinition (hudson.model.ParameterDefinition)3 ParameterValue (hudson.model.ParameterValue)3 OutputStream (java.io.OutputStream)3 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)2 Pair (com.alibaba.cobar.manager.util.Pair)2 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)2 Method (java.lang.reflect.Method)2 ParseException (java.text.ParseException)2 Iterator (java.util.Iterator)2