My favorites | Sign in
Project Logo
                
Show all Featured downloads:
filterq-0.3.zip
Blogs:
Feeds:
People details
Project owners:
  huascar.sanchez

FilterQ alleviates the pain of using multiple if-else(..) checks when iterating over a collection to obtain a smaller view of that collection.

FilterQ uses an EDSL for filtering iterable objects.

Usage Sample

 

import static com.gotobject.filter.FilterQ.*;

final Iterable<Integer> a      = Arrays.asList(1, 2, 3, 40, 20, 30, 100);
final Iterable<Integer> b      = from(a).where(gt(20).and(lt(100))).skip(1);
// result (30)

What we are writing here to FilterQ is to give me all of the elements from a that are greater than 20 and less than 100, but please, when returning the filtered iterable, skip the first element of the filtered iterable.

Another Usage Sample

 

import static com.gotobject.filter.FilterQ.*;

final Integer[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0};
final String[] strings = {"zero","one","two","three","four","five","six","seven","eight", "nine" };
final Iterable<String>  result =  from(numbers).apply(indexed(strings));

System.out.println(asList(result));
// result: five, four, one, three, nine, eight, six, seven, two, zero

This sample prints the name of each number in an integer array by indexing into a second array that contains the names.

And another one...

 

import static com.gotobject.filter.FilterQ.*;

final Iterable<Integer> n = from(range(1,1000)).where(numIsPrime()).select(not(eq(117)));
System.out.println(n);

This example will print ALL prime numbers found in the range (0...1000), but 117.









Hosted by Google Code