package com.app.baselibrary.commonUtil;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.LongSparseArray;

import com.app.baselibrary.base.app.BaseApplication;

import java.util.Collection;
import java.util.Map;

/**
 * 检验
 */
public class CheckUtil {

    public static boolean isEmpty(CharSequence str) {
        return isNull(str) || str.length() == 0;
    }

    public static boolean isEmpty(String str) {
        return isNull(str) || str.trim().length() == 0;
    }

    public static boolean isEmpty(Object[] os) {
        return isNull(os) || os.length == 0;
    }

    public static boolean isEmpty(Collection<?> l) {
        return isNull(l) || l.isEmpty() || l.size() == 0;
    }

    public static boolean isNotEmpty(Collection<?> l) {
        return !isEmpty(l);
    }

    public static boolean isNotEmpty(Map<?, ?> l) {
        return !isEmpty(l);
    }

    public static boolean isNotEmpty(LongSparseArray<?> l) {
        return !isEmpty(l);
    }

    public static boolean isEmpty(LongSparseArray<?> s) {
        return isNull(s) || s.size() <= 0;
    }

    public static boolean isEmpty(Map<?, ?> m) {
        return isNull(m) || m.isEmpty();
    }

    public static boolean isNull(Object o) {
        return o == null;
    }

    /**
     *检测apk是否正确
     * @param context
     * @param path
     * @return
     */
    public static boolean checkPackageInfo(Context context, String path){
        PackageManager pm = BaseApplication.getAppContext().getPackageManager();
        PackageInfo info = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES);
        if (info != null) {
            return true;
        }else{
            return false;
        }
    }
}
