Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Library to query Collections/Objects

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?

like image 237
dngfng Avatar asked Jul 12 '13 06:07

dngfng


People also ask

Which interface is required to use for each method on collection object?

The Collection interface is used to pass around collections of objects where maximum generality is desired. For example, by convention all general-purpose collection implementations have a constructor that takes a Collection argument.

What is query for object in java?

It is the primary class for interacting with the Query Manager (class QueryManager), which executes each query. QueryObject holds the query information read by the Query Manager, and is used to set select fields for an object and to set conditions on object fields.

What package is collections in java?

All the collection classes are present in java. util and java. util. concurrent package.

Is collection group of objects in java?

The collections in java provide an architecture to store and manipulate the group of objects, interfaces and classes. A collection is a group of objects or it is a single entity that represents multiple objects.


3 Answers

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.

like image 77
David Avatar answered Oct 02 '22 19:10

David


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.

like image 40
mthmulders Avatar answered Oct 02 '22 19:10

mthmulders


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;
    }
}
like image 44
Low Flying Pelican Avatar answered Oct 02 '22 20:10

Low Flying Pelican