This project is maintained by: Bartosz Kosarzycki
version: 0.2.3-kosiara
- filter results by nested fields inside other objects (infinite depth)
from(complexCollection).where(“complexB.testField”, eq(“SomeValue”)).all()
older versions:
- project converted to IntelliJ 13
- unique() & unique(Function<Map.Entry<T,T>, Boolean> equalsFunction)
from(dates).unique();
- startsWith comparator
from(dates).where(“name”, startsWith(“Cat”)).orderBy(“age”).all();
- ability to sort String collection without giving property/getter method name
from(dates).orderBy(Order.ASC).all();
from(from(dates).unique()).orderBy(Order.DESC).all();
- version 0.2.3-kosiara, download
- version 0.2.2-kosiara, download
- version 0.2.1-kosiara, download
I use it in Android projects to handle LINQ-like operations on collections. Works great.
A cool way to manipulate collections in Java.
Iterate over a collection is a medieval way to filtering, mapping and ordering. And with Java we are used to work like that. Coollection changes that, is the future, while closures don’t arrives for Java.
It’s easy to use. Just add import static com.wagnerandade.coollection.Coollection.*;
in your class and… More nothing!
First you need a Collection. Here we create a Animal List, and we called it animals.
List<Animal> animals;
Later you goes add a lot of animals in this list.
Now, you want to take all cats, it’s easy for Coollections! In this case, name is a method (animal.name()
).
from(animals).where("name", eq("Cat")).all();
Or, would the first animal with 2 year old? Easy too!
from(animals).where("age", eq(2)).first();
You can be more specific in your query, adding more specifications, like and and or.
from(animals).where("name", eq("Lion")).and("age", eq(2)).all(); from(animals).where("name", eq("Dog")).or("age", eq(5)).all();
There are other matchers to be precise!
eq("Cat") eqIgnoreCase("Cat") contains("og") greaterThan(3) lessThan(10) isNull()
Or a special matcher, called not.
not(eq("Bird")) not(contains("at")) not(isNull())
Order is a very interesting feature to sort your collection.
from(animals).where("name", eq("Cat")).orderBy("age").all(); from(animals).where("age", eq(5)).orderBy("name", Order.DESC).first();
You can use just order, without filter.
from(animals).orderBy("name");
Be happy!