Java Code Examples for org.apache.commons.collections.Predicate#evaluate()

The following examples show how to use org.apache.commons.collections.Predicate#evaluate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PatchRollbackPredicateTest.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void testPatchRollbackPredicateNull() {
	
	//create a new predicate
	Predicate patchRollbackPredicate = new PatchRollbackPredicate(10,2);
	
	boolean result = patchRollbackPredicate.evaluate(null);
	assertFalse("PatchRollbackPredicate returned true unexpectedly",result);
}
 
Example 2
Source File: Assert.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * @param input
 *          input to test.
 * @param predicate
 *          predicate to apply.
 * @throws IllegalArgumentException
 *           if predicate didn't rejected input.
 */
public static void assertFalse( final Object input, final Predicate predicate ) throws IllegalArgumentException {
  if ( !predicate.evaluate( input ) ) {
    return;
  }
  final StringBuilder builder = new StringBuilder();
  builder.append( "Predicate didn't rejected input [predicate=" );
  builder.append( predicate );
  builder.append( ", input=" );
  builder.append( StringUtils.abbreviate( String.valueOf( input ), INPUT_MAX_WIDTH ) );
  builder.append( "]" );
  throw new IllegalArgumentException( builder.toString() );
}
 
Example 3
Source File: Assert.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * @param input
 *          input to test.
 * @param predicate
 *          predicate to apply.
 * @throws IllegalArgumentException
 *           if predicate rejected input.
 */
public static void assertTrue( final Object input, final Predicate predicate ) throws IllegalArgumentException {
  if ( predicate.evaluate( input ) ) {
    return;
  }
  final StringBuilder builder = new StringBuilder();
  builder.append( "Predicate rejected input [predicate=" );
  builder.append( predicate );
  builder.append( ", input=" );
  builder.append( StringUtils.abbreviate( String.valueOf( input ), INPUT_MAX_WIDTH ) );
  builder.append( "]" );
  throw new IllegalArgumentException( builder.toString() );
}
 
Example 4
Source File: FunctionLoader.java    From tajo with Apache License 2.0 5 votes vote down vote up
private static Set<Method> findPublicStaticMethods(String packageName, Predicate predicate) {
  Set<Class> found = findFunctionCollections(packageName);
  Set<Method> filtered = Sets.newHashSet();

  for (Class clazz : found) {
    for (Method method : clazz.getMethods()) {
      if (isPublicStaticMethod(method) && (predicate == null || predicate.evaluate(method))) {
        filtered.add(method);
      }
    }
  }

  return filtered;
}
 
Example 5
Source File: AtlasTypeDefGraphStore.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException {
    final AtlasTypesDef typesDef = new AtlasTypesDef();
    Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter);

    for(AtlasEnumType enumType : typeRegistry.getAllEnumTypes()) {
        if (searchPredicates.evaluate(enumType)) {
            typesDef.getEnumDefs().add(enumType.getEnumDef());
        }
    }

    for(AtlasStructType structType : typeRegistry.getAllStructTypes()) {
        if (searchPredicates.evaluate(structType)) {
            typesDef.getStructDefs().add(structType.getStructDef());
        }
    }

    for(AtlasClassificationType classificationType : typeRegistry.getAllClassificationTypes()) {
        if (searchPredicates.evaluate(classificationType)) {
            typesDef.getClassificationDefs().add(classificationType.getClassificationDef());
        }
    }

    for(AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
        if (searchPredicates.evaluate(entityType)) {
            typesDef.getEntityDefs().add(entityType.getEntityDef());
        }
    }

    for(AtlasRelationshipType relationshipType : typeRegistry.getAllRelationshipTypes()) {
        if (searchPredicates.evaluate(relationshipType)) {
            typesDef.getRelationshipDefs().add(relationshipType.getRelationshipDef());
        }
    }

    return typesDef;
}
 
Example 6
Source File: PatchRollbackPredicateTest.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void testPatchRollbackPredicateWrongClass() {
	
	//create a new predicate
	Predicate patchRollbackPredicate = new PatchRollbackPredicate(10,2);
	
	boolean result = patchRollbackPredicate.evaluate(new Object());
	assertFalse("testPatchRollbackPredicateWrongClass returned true unexpectedly",result);
}
 
Example 7
Source File: KeyValueSet.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Walk entries.
 *
 * @param handler handler to call.
 * @param filter  filter to use.
 * @throws IllegalArgumentException if closure or filter is null.
 */
public void walk( final Closure handler, final Predicate filter ) throws IllegalArgumentException {
  Assert.assertNotNull( handler, "IHandler cannot be null" );
  Assert.assertNotNull( filter, "Filter cannot be null" );
  for ( KeyValue<?> keyValue : this.entries.values() ) {
    if ( filter.evaluate( keyValue ) ) {
      handler.execute( keyValue );
    }
  }
}
 
Example 8
Source File: PatchRollbackPredicateTest.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void testPredicateReturnsUpperBoundary() {
	
	//create a new predicate
	Predicate patchRollbackPredicate = new PatchRollbackPredicate(10,2);
	TestRollbackableTask1 task = new TestRollbackableTask1(10);
	
	boolean result = patchRollbackPredicate.evaluate(task);
	assertTrue("PatchRollbackPredicate returned false unexpectedly",result);
}
 
Example 9
Source File: PatchRollbackPredicateTest.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void testPredicateReturnsLowerBoundary() {
	
	//create a new predicate
	Predicate patchRollbackPredicate = new PatchRollbackPredicate(10,2);
	TestRollbackableTask1 task = new TestRollbackableTask1(2);
	
	boolean result = patchRollbackPredicate.evaluate(task);
	assertFalse("PatchRollbackPredicate returned true unexpectedly",result);
}
 
Example 10
Source File: PatchRollbackPredicateTest.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void testPredicateReturnsGreaterThanCurrent() {
	
	//create a new predicate
	Predicate patchRollbackPredicate = new PatchRollbackPredicate(10,2);
	TestRollbackableTask1 task = new TestRollbackableTask1(11);
	
	boolean result = patchRollbackPredicate.evaluate(task);
	assertFalse("PatchRollbackPredicate returned true unexpectedly",result);
}
 
Example 11
Source File: PatchRollbackPredicateTest.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void testPredicateReturnsLessThanRollback() {
	
	//create a new predicate
	Predicate patchRollbackPredicate = new PatchRollbackPredicate(10,2);
	TestRollbackableTask1 task = new TestRollbackableTask1(1);
	
	boolean result = patchRollbackPredicate.evaluate(task);
	assertFalse("PatchRollbackPredicate returned true unexpectedly",result);
}
 
Example 12
Source File: PatchRollbackPredicateTest.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void testPredicateReturnsInRange() {
	
	//create a new predicate
	Predicate patchRollbackPredicate = new PatchRollbackPredicate(10,1);
	TestRollbackableTask1 task = new TestRollbackableTask1(4);
	
	boolean result = patchRollbackPredicate.evaluate(task);
	assertTrue("PatchRollbackPredicate returned false unexpectedly",result);
}
 
Example 13
Source File: Assert.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * @param input     input to test.
 * @param predicate predicate to apply.
 * @throws IllegalArgumentException if predicate didn't rejected input.
 */
public static void assertFalse( final Object input, final Predicate predicate ) throws IllegalArgumentException {
  if ( !predicate.evaluate( input ) ) {
    return;
  }
  final StringBuilder builder = new StringBuilder();
  builder.append( "Predicate didn't rejected input [predicate=" );
  builder.append( predicate );
  builder.append( ", input=" );
  builder.append( StringUtils.abbreviate( String.valueOf( input ), INPUT_MAX_WIDTH ) );
  builder.append( "]" );
  throw new IllegalArgumentException( builder.toString() );
}
 
Example 14
Source File: Assert.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * @param input     input to test.
 * @param predicate predicate to apply.
 * @throws IllegalArgumentException if predicate rejected input.
 */
public static void assertTrue( final Object input, final Predicate predicate ) throws IllegalArgumentException {
  if ( predicate.evaluate( input ) ) {
    return;
  }
  final StringBuilder builder = new StringBuilder();
  builder.append( "Predicate rejected input [predicate=" );
  builder.append( predicate );
  builder.append( ", input=" );
  builder.append( StringUtils.abbreviate( String.valueOf( input ), INPUT_MAX_WIDTH ) );
  builder.append( "]" );
  throw new IllegalArgumentException( builder.toString() );
}
 
Example 15
Source File: AtlasTypeDefGraphStore.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
public AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException {
    final AtlasTypesDef typesDef = new AtlasTypesDef();
    Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter);

    for(AtlasEnumType enumType : typeRegistry.getAllEnumTypes()) {
        if (searchPredicates.evaluate(enumType)) {
            typesDef.getEnumDefs().add(enumType.getEnumDef());
        }
    }

    for(AtlasStructType structType : typeRegistry.getAllStructTypes()) {
        if (searchPredicates.evaluate(structType)) {
            typesDef.getStructDefs().add(structType.getStructDef());
        }
    }

    for(AtlasClassificationType classificationType : typeRegistry.getAllClassificationTypes()) {
        if (searchPredicates.evaluate(classificationType)) {
            typesDef.getClassificationDefs().add(classificationType.getClassificationDef());
        }
    }

    for(AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
        if (searchPredicates.evaluate(entityType)) {
            typesDef.getEntityDefs().add(entityType.getEntityDef());
        }
    }

    for(AtlasRelationshipType relationshipType : typeRegistry.getAllRelationshipTypes()) {
        if (searchPredicates.evaluate(relationshipType)) {
            typesDef.getRelationshipDefs().add(relationshipType.getRelationshipDef());
        }
    }

    for(AtlasBusinessMetadataType businessMetadataType : typeRegistry.getAllBusinessMetadataTypes()) {
        if (searchPredicates.evaluate(businessMetadataType)) {
            typesDef.getBusinessMetadataDefs().add(businessMetadataType.getBusinessMetadataDef());
        }
    }

    return typesDef;
}
 
Example 16
Source File: ClassUtil.java    From tajo with Apache License 2.0 4 votes vote down vote up
private static boolean isMatched(Class clazz, Class targetClass, Predicate predicate) {
  return
      !clazz.isInterface() &&
      (targetClass == null || isClassMatched(targetClass, clazz)) &&
      (predicate == null || predicate.evaluate(clazz));
}
 
Example 17
Source File: CurricularCourse.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void applyToCurricularCourses(final ExecutionYear executionYear, final Predicate predicate) {
    predicate.evaluate(this);
}
 
Example 18
Source File: KeyValueSet.java    From pentaho-kettle with Apache License 2.0 3 votes vote down vote up
/**
 * Walk entries.
 *
 * @param handler
 *          handler to call.
 * @param filter
 *          filter to use.
 * @throws IllegalArgumentException
 *           if closure or filter is null.
 */
public void walk( final Closure handler, final Predicate filter ) throws IllegalArgumentException {
  Assert.assertNotNull( handler, "Handler cannot be null" );
  Assert.assertNotNull( filter, "Filter cannot be null" );
  for ( KeyValue<?> keyValue : this.entries.values() ) {
    if ( filter.evaluate( keyValue ) ) {
      handler.execute( keyValue );
    }
  }
}