集合转换对象 对象转集合 是的我就一java填充 提取器(减少get set调用)

<dependency>
    <groupId>com.github.hioo520</groupId>
    <artifactId>collections-plus</artifactId>
    <version>1.4.0</version>
</dependency>

集合工具提取和填充器
也许对我们常常为这样的问题苦恼(不写重复的轮子提高你处理数据的能力和效率)

A.从一个Map数据中提取数据时get set 特别不方便 不烦把他转换成 entity
使用这个方法直接转换为对象类型 map--转换--->entity >>>fillEntity(Map map, Object e) 返回对象类型(哈哈接下来你就好处理了)
B.对于已经存在的List 我只想提取其中的某些数据一个或者多个key(哦还有就是我只是想提取某些key对应的value对嘞 我还想去重)
你不妨尝试下面方法:Set pickValue(List<E> list, String... parameter)--->提取某些key值(一个或者多个的key并且去重)
List<Map> pickList(List<Map> list, String... key)这个必须对于大的map我只是取特定的几个key返回给我就好了
不知道 从对象中取出几个值可不可以呢
Map pickValue(E e, String... key)而且他可以返回你想要的Map
C.对于对象拷贝我们知道用到的不是很多,可是 每次到Excel时无意间发觉我控制不了在写一个
List<E> fillClass(List<T> list, Object obj, String... param)
不好意思上面的这个方法是拷贝整个对象(其实这个就是解决excel从一个list对象到另一个list对象)
E fillClass(T e, Object obj, String... param)
这个方法才是对象对象拷贝居然支持(只拷贝其中的某些段)
D.再次掷出大招.上面的方法都支持自定义(比如 我提取出来的Map我想改动key的大小写 我想对时间做统一格式 我想对空值 空字符串 null处理 你想要的应该也都有)
E. 至于效率吗 看看下面测试结果就知道了(只是丰富了你的开发方式)

1.工具说明

  • 技术 : 反射+泛型+集合+可变参数+Threadlocal
  • 优点 :

支持所有数据类型
支持动态缓存
支持时间和key自定义
支持多线程并发
支持递归提取父类属性进行取值塞值
支持空值(防止null报异常)

2.使用方法

FillFactory.beach().需要方法见下图()
微信图片_20181030144632.png

PickFactoryTest.beach().需要方法见下图()
微信图片_20181030144632.png

3.效率效果

一千万数据map<String,Object>数据填充为对象(list<Object>)需要27秒(不存在栈溢出)

4.测试类

微信图片_20181030144632.png

/**
 * tips
 *
 * @author:hihuzi 2018/7/23 9:21
 */
public class FillFactoryTest implements Runnable {

    private MockHttpServletRequest request;

    private FillFactory fillTool;
    private static Map map;
    private static String tip;

    public void setMap(Map map) {
        this.map = map;
    }

    public void setTip(String tip) {
        this.tip = tip;
    }

    @Before
    public void setUp() {

        request = new MockHttpServletRequest();
        request.setCharacterEncoding("utf-8");
        fillTool = new FillTool();
    }

    /**
     * tips HttpServletRequest-->MAP
     *
     * @author:hihuzi 2018/7/23 15:05
     */
    @Test
    public void fill() {

        request.setParameter("integerMax", "123456");
        request.setParameter("stringMax", "你好师姐!!!");
        request.setParameter("longMax", "12.3");
        request.setParameter("intMin", "   ");
        request.setParameter("intMin", "   ");
        request.setParameter("doubleMin", "");
        /**tips 填充到request---->Map*/
        Map map = FillFactory.batch().fill(request);
        map.forEach((o, o2) -> System.out.print(o + "=" + o2 + " "));
        System.out.println("");
        /**tips 舍弃掉特定字段*/
        Map map0 = FillFactory.batch().fill(request, "stringMax");
        map0.forEach((o, o2) -> System.out.print(o + "=" + o2 + " "));
        System.out.println("");
        /**tips 舍弃掉空值*/
        Map map1 = FillFactory.batch().fill(request, new FillConfig(FillConfig.SaveStyleEnum.REMOVE_NULL_EMPTY));
        map1.forEach((o, o2) -> System.out.print(o + "=" + o2 + " "));
        System.out.println("");
        /**tips 默认属性不舍弃空值*/
        Map map2 = FillFactory.batch().fill(request, new FillConfig(FillConfig.SaveStyleEnum.DEFAULT));
        map2.forEach((o, o2) -> System.out.print(o + "=" + o2 + " "));
        System.out.println("");
        /**tips 舍弃空值 并且去掉特定字段*/
        Map map3 = FillFactory.batch().fill(request, new FillConfig(FillConfig.SaveStyleEnum.REMOVE_NULL_EMPTY), "stringMax");
        map3.forEach((o, o2) -> System.out.print(o + "=" + o2 + " "));

    }

    /**
     * tips HttpServletRequest--> obj
     * tips 对于空字符串处理
     *
     * @author:hihuzi 2018/6/14 14:50
     */
    @Test
    public void fill_entity_request() throws Exception {

        request.setParameter("booleanMax", "");
        request.setParameter("byteMax", "");
        request.setParameter("shortMax", "");
        request.setParameter("integerMax", "");
        request.setParameter("longMax", "");
        request.setParameter("floatMax", "");
        request.setParameter("doubleMax", "");
        request.setParameter("stringMax", "           ");
        request.setParameter("bigdecimalMax", "");
        request.setParameter("dateMax", "");
        request.setParameter("booleanMin", "");
        request.setParameter("charMin", "");
        request.setParameter("byteMin", "");
        request.setParameter("shortMin", "");
        request.setParameter("intMin", "");
        request.setParameter("longMin", "");
        request.setParameter("floatMin", "");
        request.setParameter("doubleMin", "");
        long start = System.currentTimeMillis();
        TestBean map1 = null;
        for (int i = 0; i < 10000000; i++) {
            map1 = FillFactory.batch().fillEntity(request, new TestBean());
        }
        long end = System.currentTimeMillis();
        System.err.println("------>一千万 耗时" + (end - start) / 1000 + "秒<------");
        System.out.println(Arrays.asList(map1));
    }

    /**
     * tips HttpServletRequest--> obj
     *
     * @author:hihuzi 2018/6/14 14:50
     */
    @Test
    public void fill_entity_request1() throws Exception {

        request.setParameter("booleanMax", "true");
        request.setParameter("byteMax", "1");
        request.setParameter("shortMax", "129");
        request.setParameter("integerMax", "123456");
        request.setParameter("longMax", "132542435");
        request.setParameter("floatMax", "12.9");
        request.setParameter("doubleMax", "3.55");
        request.setParameter("stringMax", "你好师姐!!!");
        request.setParameter("bigdecimalMax", "9825485.61551");
        request.setParameter("dateMax", "2012-12-12");
        request.setParameter("booleanMin", "true");
        request.setParameter("charMin", "a");
        request.setParameter("byteMin", "2");
        request.setParameter("shortMin", "5");
        request.setParameter("intMin", "55");
        request.setParameter("longMin", "555");
        request.setParameter("floatMin", "0.9");
        request.setParameter("doubleMin", "1.94");
        TestBean map1 = null;
        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
            map1 = FillFactory.batch().fillEntity(request, new TestBean());
        }
        long end = System.currentTimeMillis();
        System.err.println("------>一千万 耗时" + (end - start) / 1000 + "秒<------");

        System.out.println(Arrays.asList(map1).toString());
    }

    /**
     * tips HttpServletRequest--> obj
     * tips 针对不同格式针对的处理
     *
     * @author:hihuzi 2018/6/14 14:50
     */
    @Test
    public void fill_entity_request2() throws Exception {

        request.setParameter("stringMax", "你好师姐!!!");
        request.setParameter("dateMax", "2012-12-12");
        TestBean map = null;
        map = FillFactory.batch().fillEntity(request, new TestBean(),
                new FillConfig());
        System.out.println(Arrays.asList(map).toString());
        map = FillFactory.batch().fillEntity(request, new TestBean(),
                new FillConfig(FillBase.DateStyleEnum.DEFAULT.setFormartStyle("yyyy-MM-dd")));
        System.out.println(Arrays.asList(map).toString());
        request.setParameter("dateMax", "2012-12-12 22:21:20");
        map = FillFactory.batch().fillEntity(request, new TestBean(),
                new FillConfig(FillBase.DateStyleEnum.DEFAULT.setFormartStyle("yyyy-MM-dd HH:mm:ss")));
        System.out.println(Arrays.asList(map).toString());
    }

    /**
     * tips Map--> obj
     * tips 针对不同格式针对的处理
     *
     * @author:hihuzi 2018/6/14 14:50
     */
    @Test
    public void fill_entity_map() throws Exception {

        Map map = new HashMap(20);
        map.put("booleanMax", "true");
        map.put("byteMax", "1");
        map.put("shortMax", "129");
        map.put("integerMax", "123456");
        map.put("longMax", "132542435");
        map.put("floatMax", "12.99");
        map.put("stringMax", "你好师姐!!!");
        map.put("bigdecimalMax", "9825485.6");
        map.put("dateMax", "2012-12-12");
        map.put("booleanMin", "true");
        map.put("charMin", "a");
        map.put("byteMin", "2");
        map.put("shortMin", "5");
        map.put("intMin", "55");
        map.put("longMin", "555");
        map.put("floatMin", "0.9");
        map.put("doubleMin", "1.94");
        TestBean bean = FillFactory.batch().fillEntity(map, new TestBean());
        Map map1 = new HashMap(5);
        /**tips 从对象中取出map*/
        Map map2 = FillFactory.batch().fillMap(bean, map1);
        System.out.println(bean.toString());
        map2.forEach((o, o2) -> System.out.print(o + " " + o2));
    }

    /**
     * tips 针对不同时间格式处理不同时间配置(错误的属性直接丢掉)
     */
    @Test
    public void fill_entity_map0() throws Exception {

        Map map = new HashMap(20);
        map.put("stringMax", "你好师姐!!!");
        map.put("dateMax", "2012-12-12");
        /**tips 错误的属性直接丢掉*/
        map.put("dat32eMax", "2012-12-12");

        TestBean bean = FillFactory.batch().fillEntity(map, new TestBean());
        System.out.println(bean.toString() + "hashCode" + bean.hashCode());

        map.put("dateMax", "2012-12-12 24:23:22");
        TestBean bean0 = FillFactory.batch().fillEntity(map, new TestBean(),
                new FillConfig(FillBase.DateStyleEnum.DEFAULT.setFormartStyle("yyyy-MM-dd HH:mm:ss")));
        System.out.println(bean0.toString() + "hashCode" + bean.hashCode());


        Map map1 = new HashMap(5);
        /**tips 从对象中取出map*/
        Map map2 = FillFactory.batch().fillMap(bean0, map1,
                new FillConfig(FillBase.DateStyleEnum.DEFAULT.setFormartStyle("yyyy-MM-dd")));
        map2.forEach((o, o2) -> System.out.print(o + "-->" + o2));
    }


    /**
     * tips List<Map> --> E --> List<E>
     * tips 针对不同格式对应处理
     *
     * @author: hihuzi 2018/6/26 14:51
     */
    @Test
    public void fill_entity_list() throws Exception {

        List list = new ArrayList();
        List list0 = new ArrayList();
        Map map = new HashMap(20);
        map.put("booleanMax", "true");
        map.put("byteMax", "1");
        map.put("shortMax", "129");
        map.put("integerMax", "123456");
        map.put("longMax", "132542435");
        map.put("floatMax", "12.99");
        map.put("doubleMax", "3.55");
        map.put("stringMax", "你好师姐!!!");
        map.put("bigdecimalMax", "9825485.6");
        map.put("dateMax", "2012-12-12");
        map.put("booleanMin", "true");
        map.put("charMin", "a");
        map.put("byteMin", "2");
        map.put("shortMin", "5");
        map.put("intMin", "55");
        map.put("longMin", "555");
        map.put("floatMin", "0.9");
        map.put("doubleMin", "1.94");
        list.add(map);
        List<TestBean> bean = FillFactory.batch().fillEntity(list, new TestBean());
        /**tips 特殊的时间格式处理*/

        map.put("dateMax", "2012!12@12#12-12:12");
        list0.add(map);
        List<TestBean> bean0 = FillFactory.batch().fillEntity(list0, new TestBean(),
                new FillConfig(FillBase.DateStyleEnum.DEFAULT.setFormartStyle("yyyy!MM@dd#HH-mm:ss")));
        System.out.println(bean.get(0).toString());
        System.out.println(bean0.get(0).toString());
//        long start = System.currentTimeMillis();
//        List<TestBean> bean3;
//        for (int i = 0; i < 1000000; i++) {
//            bean3 = FillFactory.batch().fillEntity(list, new TestBean(),
//                    new FillConfig(FillBase.DateStyleEnum.DEFAULT.setFormartStyle("yyyy!MM@dd#HH-mm:ss")));
//        }
//        long end = System.currentTimeMillis();
//        System.err.println("------>一百万 耗时" + (end - start) / 1000 + "秒<------");
    }

    /**
     * tips list<String> --> E --> list<E> 针对数据库与实体类名有区别
     *
     * @author:hihuzi 2018/6/26 14:51
     */

    @Test
    public void fill_map() throws Exception {

        Map map = new HashMap(20);
        map.put("stringMax", "你好师姐!!!");
        map.put("dateMax", "2012-12-12");
        map.put("booleanMin", "");
        TestBean bean = FillFactory.batch().fillEntity(map, new TestBean());
        System.out.println(bean);
        Map map1 = new HashMap(5);
        /**tips 从对象中取出map*/
        map1 = FillFactory.batch().fillMap(bean, map1);
        map1.forEach((o, o2) -> System.out.print(o + "-->" + o2 + " "));
        System.out.println("");
        System.out.println("fillMap从对象中取出不为空的属性 并且时间自定义");
        map1 = FillFactory.batch().fillMap(bean, map1,
                new FillConfig(FillBase.DateStyleEnum.DEFAULT.setFormartStyle("yyyy-MM-dd HH:mm:ss")));
        map1.forEach((o, o2) -> System.out.print(o + "-->" + o2 + " "));
    }

    /**
     * tips E --> Map  针对E与map进行填充
     *
     * @parameter: E e
     * @parameter: Map map
     * @parameter: E
     * @Author: hihuzi 2018/6/26 14:51
     */

    @Test
    public void list_to_entity() throws Exception {

        List list = new ArrayList();
        list.add("true");
        list.add("1");
        list.add("129");
        list.add("123456");
        list.add("132542435");
        list.add("12.99");
        list.add("3.55");
        list.add("你好师姐!!!");
        list.add("9825485.6");
        list.add("2012-12-12");
        list.add("true");
        list.add("a");
        list.add("2");
        list.add("5");
        list.add("55");
        list.add("555");
        list.add("0.9");
        list.add("1.94");
        List<TestBean> bean = FillFactory.batch().listToEntity(list, new TestBean());
        System.out.println(bean.get(0).toString());
//        long start = System.currentTimeMillis();
//        for (int i = 0; i < 10000000; i++) {
//            List<TestBean> bean0 = FillFactory.batch().listToEntity(list, new TestBean());
//        }
//        long end = System.currentTimeMillis();
//        System.err.println("------>一千万 耗时" + (end - start) / 1000 + "秒<------");
        Map<String, Map<String, TypeCache>> classCache = ClassCache.cache;
        classCache.forEach((s, typeCache) -> System.err.println(typeCache.size()));
    }

    @Override
    public void run() {

        TestBean bean = null;
        try {
            bean = FillFactory.batch().fillEntity(map, new TestBean(),
                    new FillConfig(FillBase.DateStyleEnum.DEFAULT.setFormartStyle(this.tip)));
            System.out.println(bean.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * tips 多线程测试
     *
     * @parameter:
     * @return:
     * @author: hihuzi 2018/10/21 3:51
     */
    @Test
    public void mains() {
        Map map = new HashMap(1);
        map.put("dateMax", "333-33-33");
        FillFactoryTest test0 = new FillFactoryTest();
        test0.setMap(map);
        test0.setTip("yyyy-MM-dd");
        Map maps = new HashMap(1);
        maps.put("dateMax", "222!22@22#22-22:22");
        FillFactoryTest test = new FillFactoryTest();
        test0.setMap(maps);
        test0.setTip("yyyy!MM@dd#HH-mm:ss");
        List<Thread> threads = new ArrayList<>();
        for (int i = 0; i < 666; i++) {
            Thread thread;
            if (i % 2 == 0) {
                thread = new Thread(test0, "" + i);
            } else {
                thread = new Thread(test, "" + i);
            }
            threads.add(thread);
        }
        for (Thread thread : threads) {

            thread.start();
        }


    }

    public static void main(String[] args) {
        Map map = new HashMap(1);
        map.put("dateMax", "333-33-33");
        FillFactoryTest test0 = new FillFactoryTest();
        test0.setMap(map);
        test0.setTip("yyyy-MM-dd");
        Map maps = new HashMap(1);
        maps.put("dateMax", "222!22@22#22-22:22");
        FillFactoryTest test = new FillFactoryTest();
        test0.setMap(maps);
        test0.setTip("yyyy!MM@dd#HH-mm:ss");
        List<Thread> threads = new ArrayList<>();
        for (int i = 0; i < 666; i++) {
            Thread thread;
            if (i % 2 == 0) {
                thread = new Thread(test0, "" + i);
            } else {
                thread = new Thread(test, "" + i);
            }
            threads.add(thread);
        }
        for (Thread thread : threads) {

            thread.start();
        }

    }
}

执行结果如下:


TestBean(booleanMax=true, byteMax=1, shortMax=129, integerMax=123456, longMax=132542435, floatMax=12.99, doubleMax=3.55, stringMax=你好师姐!!!, bigdecimalMax=9825485.6, dateMax=Wed Dec 12 00:00:00 CST 2012, booleanMin=true, charMin=a, byteMin=2, shortMin=5, intMin=55, longMin=555, floatMin=0.9, doubleMin=1.94, character=null)
TestBean(booleanMax=true, byteMax=1, shortMax=129, integerMax=123456, longMax=132542435, floatMax=12.99, doubleMax=3.55, stringMax=你好师姐!!!, bigdecimalMax=9825485.6, dateMax=Wed Dec 12 12:12:12 CST 2012, booleanMin=true, charMin=a, byteMin=2, shortMin=5, intMin=55, longMin=555, floatMin=0.9, doubleMin=1.94, character=null)
TestBean(booleanMax=null, byteMax=null, shortMax=null, integerMax=null, longMax=null, floatMax=null, doubleMax=null, stringMax=你好师姐!!!, bigdecimalMax=null, dateMax=Wed Dec 12 00:00:00 CST 2012, booleanMin=false, charMin= , byteMin=0, shortMin=0, intMin=0, longMin=0, floatMin=0.0, doubleMin=0.0, character=null)hashCode-286194562
TestBean(booleanMax=null, byteMax=null, shortMax=null, integerMax=null, longMax=null, floatMax=null, doubleMax=null, stringMax=你好师姐!!!, bigdecimalMax=null, dateMax=Thu Dec 13 00:23:22 CST 2012, booleanMin=false, charMin= , byteMin=0, shortMin=0, intMin=0, longMin=0, floatMin=0.0, doubleMin=0.0, character=null)hashCode-286194562
dateMax-->2012-12-13charMin--> shortMin-->0intMin-->0doubleMin-->0.0stringMax-->你好师姐!!!byteMin-->0floatMin-->0.0booleanMin-->falselongMin-->0TestBean(booleanMax=null, byteMax=null, shortMax=null, integerMax=null, longMax=null, floatMax=null, doubleMax=null, stringMax=你好师姐!!!, bigdecimalMax=null, dateMax=Wed Dec 12 00:00:00 CST 2012, booleanMin=false, charMin= , byteMin=0, shortMin=0, intMin=0, longMin=0, floatMin=0.0, doubleMin=0.0, character=null)
dateMax-->2012-12-12 charMin-->  shortMin-->0 intMin-->0 doubleMin-->0.0 stringMax-->你好师姐!!! byteMin-->0 floatMin-->0.0 booleanMin-->false longMin-->0 
fillMap从对象中取出不为空的属性 并且时间自定义
dateMax-->2012-12-12 00:00:00 charMin-->  shortMin-->0 intMin-->0 doubleMin-->0.0 stringMax-->你好师姐!!! byteMin-->0 floatMin-->0.0 booleanMin-->false longMin-->0 [TestBean(booleanMax=null, byteMax=null, shortMax=null, integerMax=null, longMax=null, floatMax=null, doubleMax=null, stringMax=           , bigdecimalMax=null, dateMax=null, booleanMin=false, charMin= , byteMin=0, shortMin=0, intMin=0, longMin=0, floatMin=0.0, doubleMin=0.0, character=null)]
------>一千万 耗时9秒<------
------>一千万 耗时32秒<------
[TestBean(booleanMax=true, byteMax=1, shortMax=129, integerMax=123456, longMax=132542435, floatMax=12.9, doubleMax=3.55, stringMax=你好师姐!!!, bigdecimalMax=9825485.61551, dateMax=Wed Dec 12 00:00:00 CST 2012, booleanMin=true, charMin=a, byteMin=2, shortMin=5, intMin=55, longMin=555, floatMin=0.9, doubleMin=1.94, character=null)]
[TestBean(booleanMax=null, byteMax=null, shortMax=null, integerMax=null, longMax=null, floatMax=null, doubleMax=null, stringMax=你好师姐!!!, bigdecimalMax=null, dateMax=Wed Dec 12 00:00:00 CST 2012, booleanMin=false, charMin= , byteMin=0, shortMin=0, intMin=0, longMin=0, floatMin=0.0, doubleMin=0.0, character=null)]
[TestBean(booleanMax=null, byteMax=null, shortMax=null, integerMax=null, longMax=null, floatMax=null, doubleMax=null, stringMax=你好师姐!!!, bigdecimalMax=null, dateMax=Wed Dec 12 00:00:00 CST 2012, booleanMin=false, charMin= , byteMin=0, shortMin=0, intMin=0, longMin=0, floatMin=0.0, doubleMin=0.0, character=null)]
[TestBean(booleanMax=null, byteMax=null, shortMax=null, integerMax=null, longMax=null, floatMax=null, doubleMax=null, stringMax=你好师姐!!!, bigdecimalMax=null, dateMax=Wed Dec 12 22:21:20 CST 2012, booleanMin=false, charMin= , byteMin=0, shortMin=0, intMin=0, longMin=0, floatMin=0.0, doubleMin=0.0, character=null)]
longMax=12.3 integerMax=123456 intMin=    doubleMin= stringMax=你好师姐!!! 
longMax=12.3 integerMax=123456 intMin=    doubleMin= 
stringMax=你好师姐!!! longMax=12.3 integerMax=123456 
longMax=12.3 integerMax=123456 intMin=    doubleMin= stringMax=你好师姐!!! 
longMax=12.3 integerMax=123456 TestBean(booleanMax=true, byteMax=1, shortMax=129, integerMax=123456, longMax=132542435, floatMax=12.99, doubleMax=null, stringMax=你好师姐!!!, bigdecimalMax=9825485.6, dateMax=Wed Dec 12 00:00:00 CST 2012, booleanMin=true, charMin=a, byteMin=2, shortMin=5, intMin=55, longMin=555, floatMin=0.9, doubleMin=1.94, character=null)
longMax 132542435shortMin 5stringMax 你好师姐!!!byteMin 2floatMax 12.99integerMax 123456booleanMax truedateMax 2012-12-12charMin abyteMax 1intMin 55doubleMin 1.94bigdecimalMax 9825485.6floatMin 0.9booleanMin trueshortMax 129longMin 555TestBean(booleanMax=true, byteMax=1, shortMax=129, integerMax=123456, longMax=132542435, floatMax=12.99, doubleMax=3.55, stringMax=你好师姐!!!, bigdecimalMax=9825485.6, dateMax=Wed Dec 12 00:00:00 CST 2012, booleanMin=true, charMin=a, byteMin=2, shortMin=5, intMin=55, longMin=555, floatMin=0.9, doubleMin=1.94, character=null)

pick


/**
 * tips 测试工具
 *
 * @author: hihuzi 2018/7/20 8:42
 */
public class PickFactoryTest implements Runnable {


    private String tip;

    /**
     * tips  时间格式化 多级父类
     *
     * @parameter:
     * @return:
     * @author: hihuzi 2018/10/18 11:16
     */
    @Test
    public void pick0() throws Exception {


        List<TestBean> list = new ArrayList<>();
        for (int i = 2; i < 3; i++) {
            TestBean userPost = new TestBean();
            userPost.setName("你好师姐");
            userPost.setId(12345 * i + "");
            userPost.setEmail(null);
            userPost.setAddress("    ");
            list.add(userPost);
        }
        /**tips 时间格式化 多级父类*/
        List<Map> batch7 = PickFactory.batch().pick(list, new PickConfig(PickBase.SaveStyleEnum.REMOVE_NULL_EMPTY,
                PickBase.DateStyleEnum.DEFAULT.setFormartStyle("yyyy-MM-dd")), "date", "date0", "date1");
        batch7.forEach(map -> System.out.println(map));
        List<Map> batch6 = PickFactory.batch().pick(list, new PickConfig(PickBase.SaveStyleEnum.REMOVE_NULL_EMPTY,
                PickBase.DateStyleEnum.DEFAULT.setFormartStyle("yyyy-MM-dd")), "date", "date0", "date1");
        batch6.forEach(map -> System.out.println(map));
        List<Map> batch5 = PickFactory.batch().pick(list, new PickConfig(PickBase.SaveStyleEnum.REMOVE_NULL_EMPTY,
                PickBase.DateStyleEnum.DEFAULT.setFormartStyle("yyyy-MM-dd HH:mm:ss")), "date", "date0", "date1");
        batch5.forEach(map -> System.out.println(map));
        List<Map> batch4 = PickFactory.batch().pick(list, new PickConfig(PickBase.SaveStyleEnum.REMOVE_NULL_EMPTY), "date", "date0", "date1");
        batch4.forEach(map -> System.out.println(map));
    }

    @Test
    public void pick() throws Exception {

        List<TestBean> list = new ArrayList<>();
        for (int i = 2; i < 3; i++) {
            TestBean userPost = new TestBean();
            userPost.setName("你好师姐");
            userPost.setId(12345 * i + "");
            userPost.setEmail(null);
            userPost.setAddress("    ");
            list.add(userPost);
        }
        /**tips 默认转态*/
        List<Map> batch0 = PickFactory.batch().pick(list, "id", "name", "email", "address");
        batch0.forEach(map -> System.out.println(map));
        /**tips 和 默认一样 首字母大写*/
        List<Map> batch = PickFactory.batch().pick(list, new PickConfig(
                PickBase.ReturnNameEnum.INITIAL_CAPITAL), "id", "name", "email", "date");
        batch.forEach(map -> System.out.println(map));
/**         tips 空值丢掉(null 或者 "" "  ") 并且全部大写*/

        List<Map> batch3 = PickFactory.batch().pick(list, new PickConfig(
                PickBase.ReturnNameEnum.UPPER_CASE,
                PickBase.SaveStyleEnum.REMOVE_NULL_EMPTY), "id", "name", "email", "date");
        batch3.forEach(map -> System.out.println(map));
        /**tips 空值不丢掉 并且全部小写*/
        List<Map> batch2 = PickFactory.batch().pick(list, new PickConfig(
                PickBase.ReturnNameEnum.LOWER_CASE), "id", "name", "email", "date", "address");
        batch2.forEach(map -> System.out.println(map));

        /**tips 空值不丢掉 重新命名Key*/
        List<Map> batch4 = PickFactory.batch().pick(list, new PickConfig(
                PickBase.ReturnNameEnum.CUSTOM_SUFFIX.setKey("我就是我!!")), "id", "name", "email", "date", "address");
        batch4.forEach(map -> System.out.println(map));

        /**tips 时间格式化*/
        List<Map> batch5 = PickFactory.batch().pick(list, new PickConfig(
                PickBase.DateStyleEnum.DEFAULT.setFormartStyle("yyyy-MM-dd")), "date", "date0");
        batch5.forEach(map -> System.out.println(map));
    }

    /**
     * tips 同一对象集合 返回选定字段 返回value(去重)
     *
     * @author: hihuzi 2018/4/30 15:49
     */
    @Test
    public void pickValue() throws Exception {

        List<TestBean> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            TestBean userPost = new TestBean();
            userPost.setName("你好师姐" + i);
            userPost.setId(12345 * i + "");
            userPost.setEmail(null);
            userPost.setAddress("    ");
            list.add(userPost);
        }
        /**tips 默认设置*/
        Set batch1 = PickFactory.batch().pickValue(list, "id", "name", "email");
        System.out.println(Arrays.asList(batch1).toString());
        /**tips (去掉 NUll 和 "" or "      ")*/
        Set batch = PickFactory.batch().pickValue(list, new PickConfig(
                PickBase.SaveStyleEnum.REMOVE_NULL_EMPTY), "id", "name", "email", "address");
        System.out.println(Arrays.asList(batch).toString());

    }

    /**
     * tips 单个对象 返回选定字段
     *
     * @author: hihuzi 2018/4/30 15:49
     */
    @Test
    public void pickValue0() throws Exception {

        TestBean bean = new TestBean();
        bean.setName("你好师姐");
        bean.setId(UUID.randomUUID().toString());
        bean.setEmail("");
        bean.setAddress(UUID.randomUUID().toString().substring(32) + "@163.com");
        /**tips 默认 保留 空值*/
        Map batch0 = PickFactory.batch().pickValue(bean, "id", "name", "email", "date", "address");
        System.out.println(batch0.toString());
        /**tips 保留 空值*/
        Map batch1 = PickFactory.batch().pickValue(bean, new PickConfig(
                PickBase.ReturnNameEnum.DEFAULT), "id", "name", "email", "date", "address");
        System.out.println(batch1.toString());
        /**tips 舍弃 空值*/
        Map batch = PickFactory.batch().pickValue(bean, new PickConfig(
                PickBase.SaveStyleEnum.REMOVE_NULL_EMPTY), "id", "name", "email", "date", "address");
        System.out.println(batch.toString());
        Map<String, Map<String, TypeCache>> classCache = ClassCache.cache;
        classCache.forEach((s, typeCacheMap) -> System.err.println(typeCacheMap.size()));
    }

    /**
     * tips 单个对象 返回选定字段
     *
     * @author: hihuzi 2018/4/30 15:49
     */
    @Test
    public void pickMap() throws Exception {

        Map bean = new HashMap(5);
        bean.put("id", UUID.randomUUID());
        bean.put("name", "你好师姐");
        bean.put("age", "");
        bean.put("email", "54465@163.com");
        /**tips 默认 保留 空值*/
        Map batch0 = PickFactory.batch().pickMap(bean, "id", "name", "email", "age");
        System.out.println(batch0.toString());
        /**tips 保留 空值*/
        Map batch1 = PickFactory.batch().pickMap(bean, new PickConfig(
                PickBase.ReturnNameEnum.DEFAULT), "id", "name", "email", "age");
        System.out.println(batch1.toString());
        /**tips 舍弃 空值*/
        Map batch = PickFactory.batch().pickMap(bean, new PickConfig(
                PickBase.SaveStyleEnum.REMOVE_NULL_EMPTY), "id", "name", "email", "age");
        System.out.println(batch.toString());
        Map<String, Map<String, TypeCache>> classCache = ClassCache.cache;
        classCache.forEach((s, typeCacheMap) -> System.err.println(typeCacheMap.size()));
    }

    @Override
    public void run() {

        TestBean bean = new TestBean();
        bean.setDate(new Date());
        try {
            Map map = PickFactory.batch().pickValue(bean,
                    new PickConfig(PickBase.DateStyleEnum.DEFAULT.setFormartStyle(this.tip)), "date");
            System.out.println(map.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void setTip(String tip) {

        this.tip = tip;
    }

//    @Test
//    public void mutlThreadTest() {
//
//        PickFactoryTest test0 = new PickFactoryTest();
//        test0.setTip("yyyy-MM-----dd");
//        Map maps = new HashMap(1);
//        maps.put("dateMax", "2018!22@22#22-22:22");
//        PickFactoryTest test = new PickFactoryTest();
//        test.setTip("yyyy!MM@dd#HH-mm:ss");
//        List<Thread> threads = new ArrayList<>();
//        for (int i = 0; i < 666; i++) {
//            Thread thread;
//            if (i % 2 == 0) {
//                thread = new Thread(test0, "" + i);
//            } else {
//                thread = new Thread(test, "" + i);
//            }
//            threads.add(thread);
//        }
//        for (Thread thread : threads) {
//
//            thread.start();
//        }
//    }

//    public static void main(String[] args) {
//
//        PickFactoryTest test0 = new PickFactoryTest();
//        test0.setTip("yyyy-MM-----dd");
//        Map maps = new HashMap(1);
//        maps.put("dateMax", "2018!22@22#22-22:22");
//        PickFactoryTest test = new PickFactoryTest();
//        test.setTip("yyyy!MM@dd#HH-mm:ss");
//        List<Thread> threads = new ArrayList<>();
//        for (int i = 0; i < 666; i++) {
//            Thread thread;
//            if (i % 2 == 0) {
//                thread = new Thread(test0, "" + i);
//            } else {
//                thread = new Thread(test, "" + i);
//            }
//            threads.add(thread);
//        }
//        for (Thread thread : threads) {
//
//            thread.start();
//        }
//    }

}

测试结果如下

{name=你好师姐, date=2018-11-06, id=cc93df6b-17fe-4338-8dd0-c1bd8bbbe4a5, address=ed15@163.com, email=}
{name=你好师姐, date=2018-11-06, id=cc93df6b-17fe-4338-8dd0-c1bd8bbbe4a5, address=ed15@163.com, email=}
{name=你好师姐, date=2018-11-06, id=cc93df6b-17fe-4338-8dd0-c1bd8bbbe4a5, address=ed15@163.com}
[[0, null, 49380, 24690, 37035, 你好师姐0, 12345, 你好师姐4, 你好师姐3, 你好师姐2, 你好师姐1]]
[[37035, 你好师姐0, 你好师姐4, 你好师姐3, 你好师姐2, 你好师姐1, 0, 49380, 24690, 12345]]
{name=你好师姐, id=95a8d201-b307-4a7d-a093-a6759250817e, email=54465@163.com, age=}
{name=你好师姐, id=95a8d201-b307-4a7d-a093-a6759250817e, email=54465@163.com, age=}
{name=你好师姐, email=54465@163.com, id=95a8d201-b307-4a7d-a093-a6759250817e}
{name=你好师姐, id=24690, address=    , email=}
{Id=24690, Email=, Date=2018-11-06, Name=你好师姐}
5
{DATE=2018-11-06, ID=24690, NAME=你好师姐}
{name=你好师姐, date=2018-11-06, id=24690, address=    , email=}
{我就是我!!id=24690, 我就是我!!name=你好师姐, 我就是我!!date=2018-11-06, 我就是我!!email=, 我就是我!!address=    }
{date=2018-11-06, date0=2018-11-06}
{date=2018-11-06, date1=2018-11-06, date0=2018-11-06}
{date=2018-11-06, date1=2018-11-06, date0=2018-11-06}
{date=2018-11-06 22:45:57, date1=2018-11-06 22:45:57, date0=2018-11-06 22:45:57}
{date=2018-11-06, date1=2018-11-06, date0=2018-11-06}

5.readme

也是第一次在这里发点东西,希望有梦想盆友多多指点
                                                            ---hihuzi 2018-10-30 pm
如若有不足之处多多建议!
 bug无处有 鹿死谁的手!!
                                                                  ---hi@hu.zi 20.19.3.12.10.05 am

4.地址

https://github.com/hioo520/collections-plug.git
https://gitee.com/hihuzi-top/collections-plug.git

<dependency>
    <groupId>com.github.hioo520</groupId>
    <artifactId>collections-plus</artifactId>
    <version>1.4.0</version>
</dependency>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 201,924评论 5 474
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,781评论 2 378
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 148,813评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,264评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,273评论 5 363
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,383评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,800评论 3 393
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,482评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,673评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,497评论 2 318
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,545评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,240评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,802评论 3 304
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,866评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,101评论 1 258
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,673评论 2 348
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,245评论 2 341

推荐阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,081评论 1 32
  • 一、基本数据类型 注释 单行注释:// 区域注释:/* */ 文档注释:/** */ 数值 对于byte类型而言...
    龙猫小爷阅读 4,251评论 0 16
  • 一、基础知识:1、JVM、JRE和JDK的区别:JVM(Java Virtual Machine):java虚拟机...
    杀小贼阅读 2,361评论 0 4
  • 安徽省立医院南区,公开征求到该院看病的病人,就诊有不满意的,电话、书面、到办公投诉告诉该院。这种方法很好。对于该院...
    南方自媒体阅读 243评论 0 0
  • 文|龙女 字数:2502 建议阅读时间:15分钟 1. 小学六年级的夏天炽烈的阳光格外炽烈,老师和我说,“拿下这个...
    龙十五_阅读 1,953评论 16 54