package com.beagle.base.common.util;

import java.util.Iterator;
import java.util.Map;

/**
 * @author wuwanli
 */
public class StringUtils {
    public static String strip(String str) {
        return org.apache.commons.lang3.StringUtils.strip(str);
    }

    public static String trim(String str) {
        return org.apache.commons.lang3.StringUtils.trim(str);
    }

    public static boolean isNotBlank(CharSequence cs) {
        return org.apache.commons.lang3.StringUtils.isNotBlank(cs);
    }

    public static boolean isBlank(CharSequence cs) {
        return org.apache.commons.lang3.StringUtils.isBlank(cs);
    }

    public static String getRestUrlByMap(String url, Map paramMap){
        StringBuffer stringBuffer = new StringBuffer(url);
        Iterator iterator = paramMap.entrySet().iterator();
        if (iterator.hasNext()) {
            stringBuffer.append("?");
            Object element;
            while (iterator.hasNext()) {
                element = iterator.next();
                Map.Entry<String, Object> entry = (Map.Entry) element;
                //过滤value为null，value为null时进行拼接字符串会变成 "null"字符串
                if (entry.getValue() != null) {
                    stringBuffer.append(element).append("&");
                }
                url = stringBuffer.substring(0, stringBuffer.length() - 1);
            }
        }
        return url;
    }
}
