美文网首页
技术点记录20221114 Pair,TextUtils.jo

技术点记录20221114 Pair,TextUtils.jo

作者: 雨来 | 来源:发表于2022-11-14 16:11 被阅读0次

    一点点完善

    Pair

    https://www.jianshu.com/p/a9c92bf8bec5

    一个map 拼结参数的工具类:

    public final class ParamKit {
    
        public static Map<String, String> of() {
            return new HashMap<>();
        }
    
        public static Map<String, String> of(String... args) {
            List<Pair<String, String>> pairs = new ArrayList<>();
            for (int i = 0; i < args.length; i+=2) {
                pairs.add(Pair.create(args[i], args[i + 1]));
            }
            return of(pairs);
        }
    
    
        public static Map<String, String> of(List<Pair<String, String>> kvs) {
            Map<String, String> params = new HashMap<>();
            if (kvs != null && !kvs.isEmpty()) {
                for (Pair<String, String> kv : kvs) {
                    params.put(kv.first, kv.second);
                }
            }
            return params;
        }
    
        public static Map<String, String> of(Pair<String, String>... pairs) {
            if (pairs != null) {
                return of(Arrays.asList(pairs));
            }
            return of();
        }
    
    
        public static Map<String, String> page(int page, int limit, Pair<String, String>... pairs) {
            Map<String, String> params = of(Pair.create("page", "" + page), Pair.create("limit", "" + limit));
            if (pairs != null && pairs.length > 0) {
                for (Pair<String, String> kv : pairs) {
                    params.put(kv.first, kv.second);
                }
            }
            return params;
        }
    
    }
    

    使用

    ParamKit.page(0,9999,Pair.create("regionCode",regionCode),Pair.create("macCode",macCode))
    

    相关文章

      网友评论

          本文标题:技术点记录20221114 Pair,TextUtils.jo

          本文链接:https://www.haomeiwen.com/subject/aqilxdtx.html