Skip to content

Instantly share code, notes, and snippets.

@suryagaddipati
Created August 8, 2010 17:03
Show Gist options
  • Save suryagaddipati/514264 to your computer and use it in GitHub Desktop.
Save suryagaddipati/514264 to your computer and use it in GitHub Desktop.
public class IterableQuery {
public static Where from(Iterable originalCollection) {
return new Where( Iterables.transform(originalCollection, IterableQuery.SAME()));
}
private static Function SAME() {
return new Function(){
public T apply(T arg0) {
return arg0;
}
};
}
public static class SelectOrderBy{
private final Iterable iterable;
public SelectOrderBy(Iterable iteable) {
this.iterable = iteable;
}
public SelectOrderBy orderyBy( Comparator sort ){
Ordering.forComparator(sort).sort((List) iterable);
return new SelectOrderBy( iterable);
}
public Iterable select( Function function){
return Iterables.transform(iterable, function);
}
public Iterable selectEveryThing( ){
return iterable;
}
}
public static class Where{
private final Iterable iterable;
public Where(Iterable iterable) {
this.iterable = iterable;
}
public SelectOrderBy where(Predicate predicate) {
return new SelectOrderBy( Iterables.filter(iterable, predicate));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment