<commit_before>package org.djodjo.json.schema;


import org.djodjo.json.JsonElement;
import org.djodjo.json.JsonObject;
import org.djodjo.json.Validator;
import org.djodjo.json.exception.JsonException;
import org.djodjo.json.schema.validation.SchemaV5Validator;

public class SchemaV5 extends Schema {

    public SchemaV5() {
        super();
        setSchema("http://json-schema.org/draft-05/schema#");
    }

    @Override
    public Schema getEmptySchema() {
        return new SchemaV5().setSchemaFetcher(schemaFetcher);
    }

    @Override
    public Validator getDefaultValidator() {
        return new SchemaV5Validator(this);
    }


    public String getTitle(String locale) {
        String res = "";

        if (getJson().opt("title").isString()) {
            res = getJson().optString("title") ;
        } else {
            JsonObject titles = getJson().optJsonObject("title");
            if(titles!=null && titles.length()>0) {
                res = titles.optString(locale);
            } else {
                res = null;
            }
        }

        return res;
    }

    @Override
    public String getTitle() {
        String res = null;

        if(getJson().opt("title").isString()) {
            res = getJson().optString("title") ;
        } else {
            JsonObject titles = getJson().optJsonObject("title");
            if(titles!=null && titles.length()>0) {
                res = titles.valuesSet().toArray(new String[0])[0];
            } else {
                res = null;
            }
        }


        return res;
    }

    public JsonObject getTitles() {
        JsonObject res = new JsonObject();

        if(getJson().opt("title").isString()) {
            try {
                res.put("default", getJson().optString("title"));
            } catch (JsonException e) {
                e.printStackTrace();
            }
        } else {
            res = getJson().optJsonObject("title");
        }

        return res;
    }

    //replaces title if not object
    public SchemaV5 addTitle(String title, String locale) {
        JsonElement tit = getJson().opt("title");
        if(tit!=null && !tit.isJsonObject()) {
            getJson().remove("title");
            try {
                getJson().put("title", new JsonObject());
            } catch (JsonException e) {
                e.printStackTrace();
            }
        }  else if(tit==null) {
            try {
                getJson().put("title", new JsonObject());
            } catch (JsonException e) {
                e.printStackTrace();
            }
        }


        try {
            getJson().optJsonObject("title").put(locale, title);
        } catch (JsonException e) {
            e.printStackTrace();
        }
        return this;
    }
}
<commit_msg>add multiple description languages support<commit_after>package org.djodjo.json.schema;


import org.djodjo.json.JsonElement;
import org.djodjo.json.JsonObject;
import org.djodjo.json.Validator;
import org.djodjo.json.exception.JsonException;
import org.djodjo.json.schema.validation.SchemaV5Validator;

public class SchemaV5 extends Schema {

    public SchemaV5() {
        super();
        setSchema("http://json-schema.org/draft-05/schema#");
    }

    @Override
    public Schema getEmptySchema() {
        return new SchemaV5().setSchemaFetcher(schemaFetcher);
    }

    @Override
    public Validator getDefaultValidator() {
        return new SchemaV5Validator(this);
    }


    public String getTitle(String locale) {
        String res = "";

        if (getJson().opt("title").isString()) {
            res = getJson().optString("title") ;
        } else {
            JsonObject titles = getJson().optJsonObject("title");
            if(titles!=null && titles.length()>0) {
                res = titles.optString(locale);
            } else {
                res = null;
            }
        }

        return res;
    }

    @Override
    public String getTitle() {
        String res = null;

        if(getJson().opt("title").isString()) {
            res = getJson().optString("title") ;
        } else {
            JsonObject titles = getJson().optJsonObject("title");
            if(titles!=null && titles.length()>0) {
                res = titles.valuesSet().toArray(new String[0])[0];
            } else {
                res = null;
            }
        }


        return res;
    }

    public JsonObject getTitles() {
        JsonObject res = new JsonObject();

        if(getJson().opt("title").isString()) {
            try {
                res.put("default", getJson().optString("title"));
            } catch (JsonException e) {
                e.printStackTrace();
            }
        } else {
            res = getJson().optJsonObject("title");
        }

        return res;
    }

    //replaces title if not object
    public SchemaV5 addTitle(String title, String locale) {
        JsonElement tit = getJson().opt("title");
        if(tit!=null && !tit.isJsonObject()) {
            getJson().remove("title");
            try {
                getJson().put("title", new JsonObject());
            } catch (JsonException e) {
                e.printStackTrace();
            }
        }  else if(tit==null) {
            try {
                getJson().put("title", new JsonObject());
            } catch (JsonException e) {
                e.printStackTrace();
            }
        }


        try {
            getJson().optJsonObject("title").put(locale, title);
        } catch (JsonException e) {
            e.printStackTrace();
        }
        return this;
    }

    //replaces title if not object
    public SchemaV5 addDescription(String title, String locale) {
        JsonElement tit = getJson().opt("description");
        if(tit!=null && !tit.isJsonObject()) {
            getJson().remove("description");
            try {
                getJson().put("description", new JsonObject());
            } catch (JsonException e) {
                e.printStackTrace();
            }
        }  else if(tit==null) {
            try {
                getJson().put("description", new JsonObject());
            } catch (JsonException e) {
                e.printStackTrace();
            }
        }


        try {
            getJson().optJsonObject("description").put(locale, title);
        } catch (JsonException e) {
            e.printStackTrace();
        }
        return this;
    }



    public String getDescription(String locale) {
        String res = "";

        if (getJson().opt("description").isString()) {
            res = getJson().optString("description") ;
        } else {
            JsonObject titles = getJson().optJsonObject("description");
            if(titles!=null && titles.length()>0) {
                res = titles.optString(locale);
            } else {
                res = null;
            }
        }

        return res;
    }

    @Override
    public String getDescription() {
        String res = null;

        if(getJson().opt("description").isString()) {
            res = getJson().optString("description") ;
        } else {
            JsonObject titles = getJson().optJsonObject("description");
            if(titles!=null && titles.length()>0) {
                res = titles.valuesSet().toArray(new String[0])[0];
            } else {
                res = null;
            }
        }


        return res;
    }

    public JsonObject getDescriptions() {
        JsonObject res = new JsonObject();

        if(getJson().opt("description").isString()) {
            try {
                res.put("default", getJson().optString("description"));
            } catch (JsonException e) {
                e.printStackTrace();
            }
        } else {
            res = getJson().optJsonObject("description");
        }

        return res;
    }





}

{'fraction_non_alphanumeric': 0.132510183299389, 'fraction_numerical': 0.0036914460285132383, 'mean_word_length': 1.66610111978283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2368971', 'n_tokens_mistral': 2156, 'n_tokens_neox': 2057, 'n_words': 407}