ResponseLog.java 980 Bytes
package com.huaheng.mobilewms.https;

import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

public class ResponseLog {
    public static int maxSize = 50;
    public static List<String> responseList = new ArrayList<>();

    public static void add(ApiResponse apiResponse){
        try {
            if(responseList.size() >= maxSize){
                responseList.remove(responseList.size() - 1);
            }

            String responseBody = new Gson().toJson(apiResponse);
            responseList.add(0, responseBody);
        }catch (Exception e){

        }
    }

    public static void addException(String err){
        try{
            if(responseList.size() == 0){
                return;
            }
//            int target = responseList.size() - 1;
            int target = 0;
            String msg = responseList.get(target) + "\n" + err;
            responseList.set(target, msg);
        }catch (Exception e){

        }
    }
}