package com.boman.common.core.utils;

import com.alibaba.fastjson.JSONArray;
import com.boman.common.core.utils.obj.ObjectUtils;

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

/**
 * @author shiqian
 * @date 2021年03月26日 11:07
 **/
public class JSONArrayUtils {
    
    public static long[] jsonArrayToLongArray(JSONArray jsonArray){
        ObjectUtils.requireNonNull(jsonArray, "jsonArrayToLongArray jsonArray is empty");
        long[] result = new long[jsonArray.size()];
        for (int i = 0; i < jsonArray.size(); i++) {
            result[i] = jsonArray.getLong(i);
        }

        return result;
    }

    public static List<String> toList(JSONArray jsonArray){
        ObjectUtils.requireNonNull(jsonArray, "toList jsonArray is empty");
        List<String> result = new ArrayList<>(jsonArray.size());
        for (Object obj : jsonArray) {
            String obj1 = (String) obj;
            result.add(obj1);
        }
        return result;
    }

}
