Created
August 8, 2010 17:03
-
-
Save suryagaddipati/514264 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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