Search in sources :

Example 1 with Utils.checksum

use of com.ichi2.libanki.Utils.checksum in project AnkiChinaAndroid by ankichinateam.

the class Models method scmhash.

/**
 * Schema hash ***********************************************************************************************
 */
/**
 * Return a hash of the schema, to see if models are compatible.
 */
public String scmhash(Model m) {
    String s = "";
    JSONArray flds = m.getJSONArray("flds");
    for (int i = 0; i < flds.length(); ++i) {
        s += flds.getJSONObject(i).getString("name");
    }
    JSONArray tmpls = m.getJSONArray("tmpls");
    for (int i = 0; i < tmpls.length(); ++i) {
        JSONObject t = tmpls.getJSONObject(i);
        s += t.getString("name");
    }
    return Utils.checksum(s);
}
Also used : JSONObject(com.ichi2.utils.JSONObject) JSONArray(com.ichi2.utils.JSONArray)

Example 2 with Utils.checksum

use of com.ichi2.libanki.Utils.checksum in project Anki-Android by ankidroid.

the class Models method scmhash.

/*
      Schema hash ***********************************************************************************************
     */
@NonNull
@Override
public String scmhash(Model m) {
    StringBuilder s = new StringBuilder();
    JSONArray flds = m.getJSONArray("flds");
    for (JSONObject fld : flds.jsonObjectIterable()) {
        s.append(fld.getString("name"));
    }
    JSONArray tmpls = m.getJSONArray("tmpls");
    for (JSONObject t : tmpls.jsonObjectIterable()) {
        s.append(t.getString("name"));
    }
    return Utils.checksum(s.toString());
}
Also used : JSONObject(com.ichi2.utils.JSONObject) JSONArray(com.ichi2.utils.JSONArray) NonNull(androidx.annotation.NonNull)

Aggregations

JSONArray (com.ichi2.utils.JSONArray)2 JSONObject (com.ichi2.utils.JSONObject)2 NonNull (androidx.annotation.NonNull)1