package com.tofly.base.config;

/**
 * 转换分组持有者
 */
public class ConvertGroupHolder {

    private static final ThreadLocal<String[]> groupHolder = ThreadLocal.withInitial(() -> new String[]{"ALL"});

    /**
     * 设置值
     * @param group
     */
    public static void set(String[] group) {
        groupHolder.set(group);
    }

    /**
     * 清除值
     */
    public static void clear() {
        groupHolder.remove();
    }

    /**
     * 验证是否转换
     * @return
     */
    public static boolean ifConvert(String[] outerGroup) {
        String[] innerGroup = groupHolder.get();
        for (String outer : outerGroup) {
            for (String inner : innerGroup) {
                if (outer.equals(inner)) {
                    return true;
                }
            }
        }
        return false;
    }
}
