predicateusage.java

来自「这是一个关于J2EE的开源包common里的许多组件的示例应用程序,可以借鉴.」· Java 代码 · 共 53 行

JAVA
53
字号
package beanutils;

import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.PredicateUtils;
import org.apache.commons.collections.functors.InstanceofPredicate;
import org.apache.commons.collections.functors.NotNullPredicate;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;

/**
 * Title : Base Dict Class
 * Description : here Description is the function of class, here maybe multirows    
 * @author        <a href="mailto:sunpeng@china.freeborders">kevin</a> 
 * @Version       1.0 
 */

/**
 * Class description goes here.
 * @version 1.0  2005-9-22 
 * @author kevin
 */
public class PredicateUsage
{
	public static void main(String[] args)
	{

		demoPredicates();

	}

	public static void demoPredicates()
	{
		System.out.println(StringUtils.center(" demoPredicates ", 40, "="));
		Predicate p1 = new InstanceofPredicate(String.class);
		Predicate p2 = NotNullPredicate.getInstance();
		Predicate p3 = new Predicate()
		{
			public boolean evaluate(Object obj)
			{
				String str = (String)obj;
				return StringUtils.isAlphanumeric(str) && str.length() >= 6 && str.length() <= 10;
			}
		};

		Predicate p4 = PredicateUtils.allPredicate(new Predicate[]{p1, p2, p3});
		String input = "===sdf";
		Object[] raw = new Object[]{"Is '", input, "' a valid input? ", BooleanUtils.toStringYesNo(p4.evaluate(input)), "."};
		System.out.println(StringUtils.join(raw));
		System.out.println(StringUtils.repeat("=", 40));

	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?