package com.elab.redis.utils;

import org.apache.commons.beanutils.BeanUtils;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
 * 普通非容器测试
 *
 * @author ： liukx
 * @time ： 2020/7/10 - 15:02
 */
public class TestUtils {

    @Test
    public void testHashCode() {
        String json =
            " \t转换后的sql -\n" + "select\n" + "COUNT(DISTINCT created) as days\n" + "from\n" + "t_zhidi_activity_info\n"
                + "where brand_id = ? and house_id = ? and activity_id = ?\n" + "and activity_type\n"
                + "= ? and recommend_customer_id = ? and `status` = 1\n" + "and created >= ? and created <= ?1";
        String a = "Aa";
        String b = "BB";
        int aa = a.hashCode();
        int bb = b.hashCode();

        System.out.println(aa + "\t" + bb);
        System.out.println(json.hashCode());
    }

    @Test
    public void testPropertity() throws Exception {
        Map<String, String> map = new HashMap<>();
        map.put("a", "b");

        String data = "c";

        String abc = BeanUtils.getProperty(data, "abc");
        System.out.println(abc);
    }

    @Test
    public void testThread() throws Exception {
        long start = System.currentTimeMillis();
        CompletableFuture<Boolean> cf = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(5000);
                return true;
            } catch (Exception e) {
                return false;
            }
        });
        if (cf.get()) {
            long end = System.currentTimeMillis() - start;
            System.out.println("-------" + end);
        }

    }

    @Test
    public void testShorUrl() {
        int initCount = 1231212212;
        StringBuilder stringBuilder = new StringBuilder();
        String[] X36_ARRAY = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z".split(",");
        while (initCount > 0) {
            stringBuilder.append(X36_ARRAY[initCount % 36]);
            initCount = initCount / 36;
        }

        String url = stringBuilder.reverse().toString();
        System.out.println(url);
    }
}
