package com.chinaitop.depot.intelligent.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * @author qingsong.han
 * @description: 库级字符串处理工具类
 * @create 2020-09-14 11:22
 */
@Component
public class DepotStringUtil {

    // 获取两个字符串的并集(去重后取并集)
    public static String getUnion(String str1,String str2,String regex) {

        if (StringUtils.isEmpty(str1) || StringUtils.isEmpty(str2)) {
            return StringUtils.isEmpty(str1) ? str2 : str1;
        }
        StringBuilder sBuilder = new StringBuilder(str2);
        String[] array = str1.split(regex);
        for (String s : array) {
            if (StringUtils.isEmpty(s)) {
                continue;
            }
            if (!str2.contains(s)) {
                sBuilder.append(",").append(s);
            }
        }
        return sBuilder.toString();
    }

}
