5

I am looking for Java Libraries that will allow me to query collections. I have stumbled across jFilter an JoSql.

However it seems that JoSql has been inactive since 2010 and has had only 2 releases. jFilter seems to be fairly new and hasn't had any new releases since last year.

The small number of search result, when googling either of them, suggests to me that they are not used widely.

Have you got any suggestions regarding these libraries, or know of more active once?

Cœur
  • 37,241
  • 25
  • 195
  • 267
dngfng
  • 1,923
  • 17
  • 34
  • I am using `Apache commons collections`(http://commons.apache.org/proper/commons-collections/) and I am happy with this library. Also `Guava` (http://stackoverflow.com/a/14979043/1051783) provides a lot of useful APIs – gunar Jul 12 '13 at 06:36
  • You are looking most likely for something LINQ like that exists in C#. Guava is a good bet when you want to do something functional-programming like. It depends on you application but usually all these techniques are significantly slower than iterating the collection yourself. – ssindelar Jul 12 '13 at 06:40

3 Answers3

4

I have used CqEngine successfuly in my company (https://code.google.com/p/cqengine/)

When you instantiate a collection, you can easily define a set of indexes. This is much more powerful than predicates.

Also, when you will perform a search on your collection, CqEngine will not iterate on the whole collection then check if each record matches with the predicate. Instead, it will directly find the matching records in a Map like data structure. Hence you will have excellent performance.

David
  • 1,138
  • 5
  • 15
  • CqEngine looks interesting to say the least, the syntax also looks more readable than jFilter. However it seems that it only has been active for the best part of a year. No activity since December 2012 – dngfng Jul 13 '13 at 19:35
  • A Downside to CqEngine as I see it is that it does not use reflection, I do like the concept of defining the attributes. However I would hate to have to implement all those attributes for every single member in every single model that someone may want to search for. – dngfng Jul 13 '13 at 19:58
  • 1
    CQEngine is active! The last release was in December 2012 only because nobody reported bugs against that version, and it basically works for me as author. If people report bugs, there will be activity! There is support for reflection actually, see [ReflectiveAttribute](http://cqengine.googlecode.com/svn/cqengine/javadoc/apidocs/com/googlecode/cqengine/attribute/ReflectiveAttribute.html). There was discussion about features to auto-index POJOs and auto-generate attributes via annotations in the discussion group recently (July 2013), so this will lead to a new release soon (1.1 probably). – npgall Jul 15 '13 at 14:48
  • What's the memory footprint of CQEngine versus other approaches? Any notion of the point at which the size of a collection and/or the complexity of a query make using CQEngine a better choice than a) just iterating the collection and b) other approache that do similar things? I don't see any such info on the web. – mister blinky Mar 20 '14 at 13:44
  • There is a benchmark on the [CQEngine site](http://code.google.com/p/cqengine/wiki/Benchmark). Also there is discussion of memory overhead and various ways in which it can be tuned (controlling the desired tradeoff between memory usage and retrieval speed), in [IndexQuantization](http://code.google.com/p/cqengine/wiki/IndexQuantization), and in the CQEngine [forum](http://groups.google.com/group/cqengine-discuss). – npgall Apr 07 '14 at 22:58
3

You can look at Commons Collections, and more specifically CollectionUtils.filter(Collection, Filter).

Another option would be Google Guava, which has Iterables.filter(Iterable<T>, Predicate<? super T>).

The choice is yours.

mthmulders
  • 9,483
  • 4
  • 37
  • 54
  • Thanks for pointing these out. However since we are dealing with a framework witch has a whole bunch of collections cached, as in memory tables (that's just the way it is). I want to get away from hard coding the filters. – dngfng Jul 13 '13 at 19:28
2

Probably it's too late but it might be helpful for someone else, You could use,

https://code.google.com/p/joquery/

where it supports following syntax,

Collection<Dto> testList = new ArrayList<>();

Filter<Dto> query = CQ.<Dto>filter(testList)
    .where()
    .property("id").eq().value(1);
Collection<Dto> filtered = query.list();

class Dto
{
    private int id;
    private String text;

    public int getId()
    {
        return id;
    }

    public int getText()
    {
        return text;
    }
}
Low Flying Pelican
  • 5,974
  • 1
  • 32
  • 43