集合轉(zhuǎn)換對(duì)象 對(duì)象轉(zhuǎn)集合 是的我就一java填充 提取器(減少get set調(diào)用)

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

集合工具提取和填充器
也許對(duì)我們常常為這樣的問題苦惱(不寫重復(fù)的輪子提高你處理數(shù)據(jù)的能力和效率)

A.從一個(gè)Map數(shù)據(jù)中提取數(shù)據(jù)時(shí)get set 特別不方便 不煩把他轉(zhuǎn)換成 entity
使用這個(gè)方法直接轉(zhuǎn)換為對(duì)象類型 map--轉(zhuǎn)換--->entity >>>fillEntity(Map map, Object e) 返回對(duì)象類型(哈哈接下來你就好處理了)
B.對(duì)于已經(jīng)存在的List 我只想提取其中的某些數(shù)據(jù)一個(gè)或者多個(gè)key(哦還有就是我只是想提取某些key對(duì)應(yīng)的value對(duì)嘞 我還想去重)
你不妨嘗試下面方法:Set pickValue(List<E> list, String... parameter)--->提取某些key值(一個(gè)或者多個(gè)的key并且去重)
List<Map> pickList(List<Map> list, String... key)這個(gè)必須對(duì)于大的map我只是取特定的幾個(gè)key返回給我就好了
不知道 從對(duì)象中取出幾個(gè)值可不可以呢
Map pickValue(E e, String... key)而且他可以返回你想要的Map
C.對(duì)于對(duì)象拷貝我們知道用到的不是很多,可是 每次到Excel時(shí)無意間發(fā)覺我控制不了在寫一個(gè)
List<E> fillClass(List<T> list, Object obj, String... param)
不好意思上面的這個(gè)方法是拷貝整個(gè)對(duì)象(其實(shí)這個(gè)就是解決excel從一個(gè)list對(duì)象到另一個(gè)list對(duì)象)
E fillClass(T e, Object obj, String... param)
這個(gè)方法才是對(duì)象對(duì)象拷貝居然支持(只拷貝其中的某些段)
D.再次擲出大招.上面的方法都支持自定義(比如 我提取出來的Map我想改動(dòng)key的大小寫 我想對(duì)時(shí)間做統(tǒng)一格式 我想對(duì)空值 空字符串 null處理 你想要的應(yīng)該也都有)
E. 至于效率嗎 看看下面測(cè)試結(jié)果就知道了(只是豐富了你的開發(fā)方式)

1.工具說明

  • 技術(shù) : 反射+泛型+集合+可變參數(shù)+Threadlocal
  • 優(yōu)點(diǎn) :

支持所有數(shù)據(jù)類型
支持動(dòng)態(tài)緩存
支持時(shí)間和key自定義
支持多線程并發(fā)
支持遞歸提取父類屬性進(jìn)行取值塞值
支持空值(防止null報(bào)異常)

2.使用方法

FillFactory.beach().需要方法見下圖()
微信圖片_20181030144632.png

PickFactoryTest.beach().需要方法見下圖()
微信圖片_20181030144632.png

3.效率效果

一千萬數(shù)據(jù)map<String,Object>數(shù)據(jù)填充為對(duì)象(list<Object>)需要27秒(不存在棧溢出)

4.測(cè)試類

微信圖片_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 默認(rèn)屬性不舍棄空值*/
        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 對(duì)于空字符串處理
     *
     * @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("------>一千萬 耗時(shí)" + (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("------>一千萬 耗時(shí)" + (end - start) / 1000 + "秒<------");

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

    /**
     * tips HttpServletRequest--> obj
     * tips 針對(duì)不同格式針對(duì)的處理
     *
     * @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 針對(duì)不同格式針對(duì)的處理
     *
     * @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 從對(duì)象中取出map*/
        Map map2 = FillFactory.batch().fillMap(bean, map1);
        System.out.println(bean.toString());
        map2.forEach((o, o2) -> System.out.print(o + " " + o2));
    }

    /**
     * tips 針對(duì)不同時(shí)間格式處理不同時(shí)間配置(錯(cuò)誤的屬性直接丟掉)
     */
    @Test
    public void fill_entity_map0() throws Exception {

        Map map = new HashMap(20);
        map.put("stringMax", "你好師姐!!!");
        map.put("dateMax", "2012-12-12");
        /**tips 錯(cuò)誤的屬性直接丟掉*/
        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 從對(duì)象中取出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 針對(duì)不同格式對(duì)應(yīng)處理
     *
     * @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 特殊的時(shí)間格式處理*/

        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("------>一百萬 耗時(shí)" + (end - start) / 1000 + "秒<------");
    }

    /**
     * tips list<String> --> E --> list<E> 針對(duì)數(shù)據(jù)庫與實(shí)體類名有區(qū)別
     *
     * @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 從對(duì)象中取出map*/
        map1 = FillFactory.batch().fillMap(bean, map1);
        map1.forEach((o, o2) -> System.out.print(o + "-->" + o2 + " "));
        System.out.println("");
        System.out.println("fillMap從對(duì)象中取出不為空的屬性 并且時(shí)間自定義");
        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  針對(duì)E與map進(jìn)行填充
     *
     * @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("------>一千萬 耗時(shí)" + (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 多線程測(cè)試
     *
     * @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();
        }

    }
}

執(zhí)行結(jié)果如下:


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從對(duì)象中取出不為空的屬性 并且時(shí)間自定義
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)]
------>一千萬 耗時(shí)9秒<------
------>一千萬 耗時(shí)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 測(cè)試工具
 *
 * @author: hihuzi 2018/7/20 8:42
 */
public class PickFactoryTest implements Runnable {


    private String tip;

    /**
     * tips  時(shí)間格式化 多級(jí)父類
     *
     * @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 時(shí)間格式化 多級(jí)父類*/
        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 默認(rèn)轉(zhuǎn)態(tài)*/
        List<Map> batch0 = PickFactory.batch().pick(list, "id", "name", "email", "address");
        batch0.forEach(map -> System.out.println(map));
        /**tips 和 默認(rèn)一樣 首字母大寫*/
        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 時(shí)間格式化*/
        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 同一對(duì)象集合 返回選定字段 返回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 默認(rèn)設(shè)置*/
        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 單個(gè)對(duì)象 返回選定字段
     *
     * @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 默認(rèn) 保留 空值*/
        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 單個(gè)對(duì)象 返回選定字段
     *
     * @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 默認(rèn) 保留 空值*/
        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();
//        }
//    }

}

測(cè)試結(jié)果如下

{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

也是第一次在這里發(fā)點(diǎn)東西,希望有夢(mèng)想盆友多多指點(diǎn)
                                                            ---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>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末敬察,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌矮瘟,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,123評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件泻云,死亡現(xiàn)場(chǎng)離奇詭異切平,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)脆诉,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,031評(píng)論 2 384
  • 文/潘曉璐 我一進(jìn)店門甚亭,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人击胜,你說我怎么就攤上這事亏狰。” “怎么了偶摔?”我有些...
    開封第一講書人閱讀 156,723評(píng)論 0 345
  • 文/不壞的土叔 我叫張陵暇唾,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我辰斋,道長(zhǎng)策州,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,357評(píng)論 1 283
  • 正文 為了忘掉前任宫仗,我火速辦了婚禮够挂,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘藕夫。我一直安慰自己孽糖,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,412評(píng)論 5 384
  • 文/花漫 我一把揭開白布毅贮。 她就那樣靜靜地躺著办悟,像睡著了一般。 火紅的嫁衣襯著肌膚如雪滩褥。 梳的紋絲不亂的頭發(fā)上病蛉,一...
    開封第一講書人閱讀 49,760評(píng)論 1 289
  • 那天,我揣著相機(jī)與錄音瑰煎,去河邊找鬼铺然。 笑死,一個(gè)胖子當(dāng)著我的面吹牛丢间,可吹牛的內(nèi)容都是我干的探熔。 我是一名探鬼主播,決...
    沈念sama閱讀 38,904評(píng)論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼烘挫,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼诀艰!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起饮六,我...
    開封第一講書人閱讀 37,672評(píng)論 0 266
  • 序言:老撾萬榮一對(duì)情侶失蹤其垄,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后卤橄,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體绿满,經(jīng)...
    沈念sama閱讀 44,118評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,456評(píng)論 2 325
  • 正文 我和宋清朗相戀三年窟扑,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了喇颁。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片漏健。...
    茶點(diǎn)故事閱讀 38,599評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖橘霎,靈堂內(nèi)的尸體忽然破棺而出蔫浆,到底是詐尸還是另有隱情,我是刑警寧澤姐叁,帶...
    沈念sama閱讀 34,264評(píng)論 4 328
  • 正文 年R本政府宣布瓦盛,位于F島的核電站,受9級(jí)特大地震影響外潜,放射性物質(zhì)發(fā)生泄漏原环。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,857評(píng)論 3 312
  • 文/蒙蒙 一处窥、第九天 我趴在偏房一處隱蔽的房頂上張望嘱吗。 院中可真熱鬧,春花似錦碧库、人聲如沸柜与。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,731評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至颅悉,卻和暖如春沽瞭,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背剩瓶。 一陣腳步聲響...
    開封第一講書人閱讀 31,956評(píng)論 1 264
  • 我被黑心中介騙來泰國(guó)打工驹溃, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人延曙。 一個(gè)月前我還...
    沈念sama閱讀 46,286評(píng)論 2 360
  • 正文 我出身青樓豌鹤,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親枝缔。 傳聞我的和親對(duì)象是個(gè)殘疾皇子布疙,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,465評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容

  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴(yán)謹(jǐn) 對(duì)...
    cosWriter閱讀 11,090評(píng)論 1 32
  • 一灵临、基本數(shù)據(jù)類型 注釋 單行注釋:// 區(qū)域注釋:/* */ 文檔注釋:/** */ 數(shù)值 對(duì)于byte類型而言...
    龍貓小爺閱讀 4,257評(píng)論 0 16
  • 一、基礎(chǔ)知識(shí):1趴荸、JVM儒溉、JRE和JDK的區(qū)別:JVM(Java Virtual Machine):java虛擬機(jī)...
    殺小賊閱讀 2,369評(píng)論 0 4
  • 安徽省立醫(yī)院南區(qū),公開征求到該院看病的病人发钝,就診有不滿意的顿涣,電話波闹、書面、到辦公投訴告訴該院涛碑。這種方法很好舔痪。對(duì)于該院...
    南方自媒體閱讀 245評(píng)論 0 0
  • 文|龍女 字?jǐn)?shù):2502 建議閱讀時(shí)間:15分鐘 1. 小學(xué)六年級(jí)的夏天熾烈的陽光格外熾烈,老師和我說锄码,“拿下這個(gè)...
    龍十五_閱讀 1,960評(píng)論 16 54