Apache的commons之函数式编程Predicate与Transformer (一)

这篇博客探讨了Apache Commons库中Predicate和Transformer的概念及其应用。首先介绍了Predicate的简单用法,它在函数式编程中用于判断条件。接着详细阐述了Transformer如何将数据转化为指定类型,帮助优化数据处理流程。文章特别提醒读者使用的是commons-collections4-4.1.jar版本。
摘要由CSDN通过智能技术生成

 注意  : 我使用jar包是commons-collections4-4.1.jar appache下的 各位不要导错

 

Predicate简单的使用

 

package com.hp.common;

import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections4.PredicateUtils;
import org.apache.commons.collections4.functors.EqualPredicate;
import org.apache.commons.collections4.functors.NotNullPredicate;
import org.apache.commons.collections4.functors.UniquePredicate;
import org.apache.commons.collections4.list.PredicatedList;
import org.apache.commons.collections4.map.PredicatedMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 函数式编程 -->Predicate
 */
public class Demo01 {
    public static void main(String[] args) {
        System.out.println("######相等判断");
        boolean equalsePredicate = equalePredicate();
        System.out.println(equalsePredicate);
        System.out.println("####为空判断");
        boolean str = notNull(null);
        System.out.println(str);
        System.out.println("####对集合进行的操作  判断集合是否为空");
        predicateList();

        System.out.println("####判断map是否为空");
        predicateMap();


        System.out.println("######唯一性判断");
        unionPredicate();

        System.out.println("#####z自定义验证");
        customPridicate();
    }


    /**
     * 比较相等的判断 相等返回true  不等返回false
     *
     * @return
     */
    public static boolean equalePredicate() {
        //相当于if  else 的替代
        //第一种需要 new EqualPredicate<String>("hello")
        // Predicate<String> hello = new EqualPredicate<String>("hello");
        //第二种 不需要new 对象 里面有封装好的方法
        Predicate<String> hello = EqualPredicate.equalPredicate("hello");
        //判断是否相等
        return hello.evaluate("hello");
    }

    /**
     * 对单个字符  进行判断是否为空  如果不为空返回true 为空返回false
     *
     * @param str
     * @return
     */
    public static boolea
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值