Untitled

 avatar
unknown
plain_text
a month ago
10 kB
3
Indexable
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;

class Model {
    static class jsonValue {
        String JsonVal = "";
        jsonObject JsonObj = new jsonObject();
        jsonArray JsonArr = new jsonArray();
        int type;

        static class jsonObject {
            HashMap<String, jsonValue> JsonObjhash = new HashMap<>();
            public static ArrayList<String> splitobject(String a, String check) {
                ArrayList<String> javab = new ArrayList<>();
                for (int i = 0; i < a.length(); i++) {
                    if (check.charAt(i) == '0' && a.charAt(i) == ':') {
                        String l = a.substring(0, i);
                        String l2 = a.substring(i + 1, a.length());
                        String l3 = check.substring(i + 1, a.length());
                        javab.add(l);
                        javab.add(l2);
                        javab.add(l3);
                        return javab;
                    }
                }
                javab.add("null");
                javab.add("mds");
                javab.add("fknd");
                return javab;
            }
            public static jsonObject buildjsonobject(String a, String check) {
                ArrayList<ArrayList<String>> javab = narahat(a, check);
                jsonObject javabf = new jsonObject();
                if (javab.isEmpty()) return javabf;
                ArrayList<String> javab2 = new ArrayList<>(javab.get(0));
                ArrayList<String> javab3 = new ArrayList<>(javab.get(1));
                for (int i = 0; i < javab2.size(); i++) {
                    ArrayList<String> mo = new ArrayList<>();
                    mo = splitobject(javab2.get(i), javab3.get(i));
                    String key = mo.get(0);
                    jsonValue value = buildjsonvalue(mo.get(1), mo.get(2));
                    javabf.JsonObjhash.put(key, value);
                }
                return javabf;
            }
        }

        static class jsonArray {
            ArrayList<jsonValue> JsonArr = new ArrayList<>();
            public static jsonArray buildjsonarray(String a, String check) {
                ArrayList<ArrayList<String>> javab = new ArrayList<>();
                javab = narahat(a, check);
                ArrayList<String> javab2 = new ArrayList<>();
                ArrayList<String> javab3 = new ArrayList<>();
                javab2 = javab.get(0);
                javab3 = javab.get(1);
                jsonArray javabf = new jsonArray();
                for (int i = 0; i < javab2.size(); i++) {
                    jsonValue jv = buildjsonvalue(javab2.get(i), javab3.get(i));
                    javabf.JsonArr.add(jv);
                }
                return javabf;
            }
        }

        public static ArrayList<ArrayList<String>> narahat(String a, String check) {
            ArrayList<String> javab = new ArrayList<>();
            ArrayList<String> javab2 = new ArrayList<>();
            ArrayList<ArrayList<String>> javabf = new ArrayList<>();
            if (a.length() == 2) return javabf;
            int counterA = 0;
            int counterK = 0;
            String za = "";
            String add = "";
            for (int i = 1; i < a.length() - 1; i++) {
                if (check.charAt(i) == '0') {
                    if (a.charAt(i) == '{') {
                        counterA++;
                    }
                    if (a.charAt(i) == '}') {
                        counterA--;
                    }
                    if (a.charAt(i) == '[') {
                        counterK++;
                    }
                    if (a.charAt(i) == ']') {
                        counterK--;
                    }
                }
                if (counterA == 0 && counterK == 0 && check.charAt(i) == '0') {
                    if (a.charAt(i) == ',') {
                        javab.add(za);
                        javab2.add(add);
                        za = "";
                        add = "";
                        continue;
                    }
                }
                add += check.charAt(i);
                za += a.charAt(i);
            }
            javab.add(za);
            javab2.add(add);
            javabf.add(javab);
            javabf.add(javab2);
            return javabf;
        }

        public static String dalqak(String a) {
            String javab = "";
            boolean test = false;
            for (int i = 0; i < a.length(); i++) {
                if (a.charAt(i) == '\\') {
                    javab += "11";
                    i++;
                    continue;
                }
                if (a.charAt(i) == '"') {
                    if (!test) {
                        test = true;
                        javab += "0";
                    } else {
                        test = false;
                        javab += "0";
                    }
                } else if (test) {
                    javab += "1";
                } else {
                    javab += "0";
                }
            }
            return javab;
        }

        public static int isjsonvalue(String a, String check) {
            if (a.charAt(0) == '{') {
                return 2;
            }
            if (a.charAt(0) == '[') {
                return 3;
            }
            else return 1;
        }

        public static jsonValue buildjsonvalue(String a, String check) {
            int l = isjsonvalue(a, check);
            jsonValue javab = new jsonValue();
            javab.type = l;
            if (l == 0) {
                System.out.println(0);
                System.exit(0);
            }
            if (l == 1) {
                javab.JsonVal = a;
            }
            if (l == 2) {
                javab.JsonArr = jsonArray.buildjsonarray(a, check);
            }
            if (l == 3) {
                javab.JsonObj = jsonObject.buildjsonobject(a, check);
            }
            return javab;
        }

        public static String jsonvaluetostring(jsonValue a) {
            String l = "";
            if (a.type == 1) {
                l += a.JsonVal;
            } else if (a.type == 2) {
                int p = 0;
                l += '{';
                for (String it : a.JsonObj.JsonObjhash.keySet()) {
                    l += '"' + it + '"';
                    l += ':';
                    l += jsonvaluetostring(a.JsonObj.JsonObjhash.get(it));
                    if (p != a.JsonObj.JsonObjhash.keySet().size() - 1) {
                        l += ',';
                    }
                    p++;
                }
                l += '}';
            } else if (a.type == 3) {
                int p = 0;
                l += '[';
                for (int i = 0; i < a.JsonArr.JsonArr.size(); i++) {
                    l += jsonvaluetostring(a.JsonArr.JsonArr.get(i));
                    if (p != a.JsonObj.JsonObjhash.keySet().size() - 1) {
                        l += ',';
                    }
                    p++;
                }
                l += ']';
            }
            return l;
        }

        public static jsonValue datatojsonvalue(ArrayList<user> users) {
            jsonValue javab = new jsonValue();
            javab.type = 2;
            HashMap<String, jsonValue> javab2 = javab.JsonObj.JsonObjhash;
            for (int i = 0; i < users.size(); i++) {
                jsonValue temp = new jsonValue();
                temp.type = 2;
                jsonValue temp2 = new jsonValue();
                temp2.type = 1;
                jsonValue temp3 = new jsonValue();
                temp3.type = 2;
                temp2.JsonVal = String.valueOf(users.get(i).balance);
                for (int j = 0; j < users.get(i).history.size(); j++) {
                    tara taratemp = users.get(i).history.get(j);
                    jsonValue tempx = new jsonValue();
                    jsonValue tempx2 = new jsonValue();
                    jsonValue tempx3 = new jsonValue();
                    jsonValue tempx4 = new jsonValue();
                    jsonValue tempx5 = new jsonValue();
                    tempx2.JsonVal = taratemp.type;
                    tempx3.JsonVal = taratemp.first;
                    tempx5.JsonVal = taratemp.date;
                    tempx4.JsonVal = String.valueOf(taratemp.balance);
                    tempx2.type = 1;
                    tempx3.type = 1;
                    tempx4.type = 1;
                    tempx5.type = 1;
                    tempx.type = 3;
                    tempx.JsonArr.JsonArr.add(tempx2);
                    tempx.JsonArr.JsonArr.add(tempx3);
                    tempx.JsonArr.JsonArr.add(tempx4);
                    tempx.JsonArr.JsonArr.add(tempx5);
                    temp3.JsonObj.JsonObjhash.put(String.valueOf(taratemp.id), tempx);
                }
                temp.JsonObj.JsonObjhash.put("balance", temp2);
                temp.JsonObj.JsonObjhash.put("transaction", temp3);
                javab2.put(users.get(i).name, temp);
            }
            javab.JsonObj.JsonObjhash = javab2;
            return javab;
        }
    }


}
class user {
    String password;
    String name;
    double balance;
    ArrayList<tara> history = new ArrayList<>();
    public user(String name, String password, double balance) {
        this.name = name;
        this.password = password;
        this.balance = balance;
    }
}

class tara {
    String type;
    double balance;
    String date;
    String first;
    LocalDateTime now = LocalDateTime.now();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss");
    String time = now.format(formatter);
    public tara(String type, double balance, String first){
        this.balance = balance;
        this.type = type;
        this.date = time;
        this.first = first;
    }
}
Editor is loading...
Leave a Comment