Update of /cvsroot/hibernate/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24797/metadata/src/test/org/hibernate/test/reflection/java
Added Files:
ComprehensionTest.java
Log Message:
Collection comprehension utilities
--- NEW FILE: ComprehensionTest.java ---
package org.hibernate.test.reflection.java;
import java.util.LinkedList;
import java.util.List;
import org.hibernate.reflection.java.Comprehension;
import org.hibernate.reflection.java.Condition;
import junit.framework.TestCase;
/**
* @author Paolo Perrotta
*/
public class ComprehensionTest extends TestCase {
public void testAppliesComprehensionToACollection() {
List<Integer> allItems = new LinkedList<Integer>();
allItems.add( -1 );
allItems.add( 2 );
// We want a new list that contains all the integers greater than zero
// from the original list. With comprehension, we can do this in a
// single instruction:
List<Integer> selectedItems = Comprehension.select( allItems, new Condition<Integer>() {
public boolean applyTo(Integer item) {
return item > 0;
}
} );
assertEquals( 1, selectedItems.size() );
assertTrue( allItems.contains( 2 ) );
}
}
|