org.apache.commons.collections.Predicate.evaluate()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中org.apache.commons.collections.Predicate.evaluate()方法的一些代码示例,展示了Predicate.evaluate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Predicate.evaluate()方法的具体详情如下:
包路径:org.apache.commons.collections.Predicate
类名称:Predicate
方法名:evaluate

Predicate.evaluate介绍

[英]Use the specified parameter to perform a test that returns true or false.
[中]使用指定的参数执行返回true或false的测试。

代码示例

代码示例来源:origin: commons-collections/commons-collections

/**
 * Evaluates the predicate returning true if both predicates return true.
 * 
 * @param object  the input object
 * @return true if both decorated predicates return true
 */
public boolean evaluate(Object object) {
  return (iPredicate1.evaluate(object) && iPredicate2.evaluate(object));
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Evaluates the predicate returning the opposite to the stored predicate.
 * 
 * @param object  the input object
 * @return true if predicate returns false
 */
public boolean evaluate(Object object) {
  return !(iPredicate.evaluate(object));
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Executes the true or false closure accoring to the result of the predicate.
 * 
 * @param input  the input object
 */
public void execute(Object input) {
  if (iPredicate.evaluate(input) == true) {
    iTrueClosure.execute(input);
  } else {
    iFalseClosure.execute(input);
  }
}

代码示例来源:origin: commons-collections/commons-collections

public void testInvokerPredicate() {
  List list = new ArrayList();
  assertEquals(true, PredicateUtils.invokerPredicate("isEmpty").evaluate(list));
  list.add(new Object());
  assertEquals(false, PredicateUtils.invokerPredicate("isEmpty").evaluate(list));
}

代码示例来源:origin: commons-collections/commons-collections

public void testInvokerPredicate2() {
  List list = new ArrayList();
  assertEquals(false, PredicateUtils.invokerPredicate(
    "contains", new Class[] {Object.class}, new Object[] {cString}).evaluate(list));
  list.add(cString);
  assertEquals(true, PredicateUtils.invokerPredicate(
    "contains", new Class[] {Object.class}, new Object[] {cString}).evaluate(list));
}

代码示例来源:origin: commons-collections/commons-collections

public void testInvokerPredicateEx3() {
  try {
    PredicateUtils.invokerPredicate("noSuchMethod").evaluate(new Object());
  } catch (FunctorException ex) {
    return;
  }
  fail();
}

代码示例来源:origin: commons-collections/commons-collections

public void testInvokerPredicate2Ex2() {
  try {
    PredicateUtils.invokerPredicate("contains", new Class[] {Object.class}, new Object[] {cString}).evaluate(null);
  } catch (FunctorException ex) {
    return;
  }
  fail();
}

代码示例来源:origin: commons-collections/commons-collections

public void testIdentityPredicate() {
  assertSame(PredicateUtils.nullPredicate(), PredicateUtils.identityPredicate(null));
  assertNotNull(PredicateUtils.identityPredicate(new Integer(6)));
  assertEquals(false, PredicateUtils.identityPredicate(new Integer(6)).evaluate(null));
  assertEquals(false, PredicateUtils.identityPredicate(new Integer(6)).evaluate(cObject));
  assertEquals(false, PredicateUtils.identityPredicate(new Integer(6)).evaluate(cString));
  assertEquals(false, PredicateUtils.identityPredicate(new Integer(6)).evaluate(cInteger));
  assertEquals(true, PredicateUtils.identityPredicate(cInteger).evaluate(cInteger));
}

代码示例来源:origin: commons-collections/commons-collections

public void testEqualPredicate() {
  assertSame(PredicateUtils.nullPredicate(), PredicateUtils.equalPredicate(null));
  assertNotNull(PredicateUtils.equalPredicate(new Integer(6)));
  assertEquals(false, PredicateUtils.equalPredicate(new Integer(6)).evaluate(null));
  assertEquals(false, PredicateUtils.equalPredicate(new Integer(6)).evaluate(cObject));
  assertEquals(false, PredicateUtils.equalPredicate(new Integer(6)).evaluate(cString));
  assertEquals(true, PredicateUtils.equalPredicate(new Integer(6)).evaluate(cInteger));
}

代码示例来源:origin: commons-collections/commons-collections

public void testNullIsTruePredicate() {
  assertEquals(true, PredicateUtils.nullIsTruePredicate(PredicateUtils.truePredicate()).evaluate(null));
  assertEquals(true, PredicateUtils.nullIsTruePredicate(PredicateUtils.truePredicate()).evaluate(new Object()));
  assertEquals(false, PredicateUtils.nullIsTruePredicate(PredicateUtils.falsePredicate()).evaluate(new Object()));
}

代码示例来源:origin: commons-collections/commons-collections

public void testNullIsExceptionPredicate() {
  assertEquals(true, PredicateUtils.nullIsExceptionPredicate(PredicateUtils.truePredicate()).evaluate(new Object()));
  try {
    PredicateUtils.nullIsExceptionPredicate(PredicateUtils.truePredicate()).evaluate(null);
  } catch (FunctorException ex) {
    return;
  }
  fail();
}

代码示例来源:origin: commons-collections/commons-collections

public void testAsPredicateTransformerEx2() {
  try {
    PredicateUtils.asPredicate(TransformerUtils.nopTransformer()).evaluate(null);
  } catch (FunctorException ex) {
    return;
  }
  fail();
}

代码示例来源:origin: commons-collections/commons-collections

public void testFalsePredicate() {
  assertNotNull(PredicateUtils.falsePredicate());
  assertSame(PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate());
  assertEquals(false, PredicateUtils.falsePredicate().evaluate(null));
  assertEquals(false, PredicateUtils.falsePredicate().evaluate(cObject));
  assertEquals(false, PredicateUtils.falsePredicate().evaluate(cString));
  assertEquals(false, PredicateUtils.falsePredicate().evaluate(cInteger));
}

代码示例来源:origin: commons-collections/commons-collections

public void testNullPredicate() {
  assertNotNull(PredicateUtils.nullPredicate());
  assertSame(PredicateUtils.nullPredicate(), PredicateUtils.nullPredicate());
  assertEquals(true, PredicateUtils.nullPredicate().evaluate(null));
  assertEquals(false, PredicateUtils.nullPredicate().evaluate(cObject));
  assertEquals(false, PredicateUtils.nullPredicate().evaluate(cString));
  assertEquals(false, PredicateUtils.nullPredicate().evaluate(cInteger));
}

代码示例来源:origin: commons-collections/commons-collections

public void testIsNotNullPredicate() {
  assertNotNull(PredicateUtils.notNullPredicate());
  assertSame(PredicateUtils.notNullPredicate(), PredicateUtils.notNullPredicate());
  assertEquals(false, PredicateUtils.notNullPredicate().evaluate(null));
  assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cObject));
  assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cString));
  assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cInteger));
}

代码示例来源:origin: commons-collections/commons-collections

public void testTruePredicate() {
  assertNotNull(PredicateUtils.truePredicate());
  assertSame(PredicateUtils.truePredicate(), PredicateUtils.truePredicate());
  assertEquals(true, PredicateUtils.truePredicate().evaluate(null));
  assertEquals(true, PredicateUtils.truePredicate().evaluate(cObject));
  assertEquals(true, PredicateUtils.truePredicate().evaluate(cString));
  assertEquals(true, PredicateUtils.truePredicate().evaluate(cInteger));
}

代码示例来源:origin: commons-collections/commons-collections

public void testNotPredicate() {
  assertNotNull(PredicateUtils.notPredicate(PredicateUtils.truePredicate()));
  assertEquals(false, PredicateUtils.notPredicate(PredicateUtils.truePredicate()).evaluate(null));
  assertEquals(false, PredicateUtils.notPredicate(PredicateUtils.truePredicate()).evaluate(cObject));
  assertEquals(false, PredicateUtils.notPredicate(PredicateUtils.truePredicate()).evaluate(cString));
  assertEquals(false, PredicateUtils.notPredicate(PredicateUtils.truePredicate()).evaluate(cInteger));
}

代码示例来源:origin: commons-collections/commons-collections

public void testOrPredicate() {
  assertEquals(true, PredicateUtils.orPredicate(PredicateUtils.truePredicate(), PredicateUtils.truePredicate()).evaluate(null));
  assertEquals(true, PredicateUtils.orPredicate(PredicateUtils.truePredicate(), PredicateUtils.falsePredicate()).evaluate(null));
  assertEquals(true, PredicateUtils.orPredicate(PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()).evaluate(null));
  assertEquals(false, PredicateUtils.orPredicate(PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate()).evaluate(null));
}

代码示例来源:origin: commons-collections/commons-collections

public void testEitherPredicate() {
  assertEquals(false, PredicateUtils.eitherPredicate(PredicateUtils.truePredicate(), PredicateUtils.truePredicate()).evaluate(null));
  assertEquals(true, PredicateUtils.eitherPredicate(PredicateUtils.truePredicate(), PredicateUtils.falsePredicate()).evaluate(null));
  assertEquals(true, PredicateUtils.eitherPredicate(PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()).evaluate(null));
  assertEquals(false, PredicateUtils.eitherPredicate(PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate()).evaluate(null));
}

代码示例来源:origin: commons-collections/commons-collections

public void testAndPredicate() {
  assertEquals(true, PredicateUtils.andPredicate(PredicateUtils.truePredicate(), PredicateUtils.truePredicate()).evaluate(null));
  assertEquals(false, PredicateUtils.andPredicate(PredicateUtils.truePredicate(), PredicateUtils.falsePredicate()).evaluate(null));
  assertEquals(false, PredicateUtils.andPredicate(PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()).evaluate(null));
  assertEquals(false, PredicateUtils.andPredicate(PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate()).evaluate(null));
}

相关文章

Predicate类方法