Quaere - Does anyone else use it? (LINQ to Objects for Java)

I am originally a .NET guy recently working in Java and find that I really lack LINQ to Objects, especially for filtering by collection.

A few people here on Stack Overflow answered "LINQ for Java"? question in one word:

Quaere

However, the site clearly stated “Pre-Beta,” and there were no commits to their code during the year, so I guess the project is pretty much dead.

Does anyone really use this and / or have any experience?

The second most common answer is to use Google Collections. Is this the most suitable Java way?

Greetings

Marty

+5
5

Quaere LINQ Java, , LINQ.

Querydsl , .

JPA/Hibernate, JDO SQL-.

SQL , - -where-list.

Querydsl, .

+3

Linq To Objects , , Java, :

Vector<Integer> numbers = new Vector<Integer>();

numbers.add(42);
numbers.add(3);
numbers.add(16);
numbers.add(92);
numbers.add(9);

Iterable<Integer> filtered = new Where<Integer>(numbers) {
    protected boolean predicate(Integer i) { return i > 10; }
};

Iterable<String> converted = new Select<Integer, String>(filtered) {
    protected String select(Integer i) { return i.toString(); }
};

for (final String str : converted)
    System.out.println(str);

, Where Select. filtered , , , , () . . , . , , final s, ( lambdas #).

- . , Java , ( ) , , , , . , , new Select(filtered) - .

Select Where:

abstract class Select<TSource, TResult> implements Iterable<TResult>
{
    private Iterable<TSource> _source;

    public Select(Iterable<TSource> source)
        { _source = source; }

    private class Iter implements Iterator<TResult>
    {
        private Iterator<TSource> _i;

        public Iter() { _i = _source.iterator(); }

        public void remove()
            { _i.remove(); }

        public boolean hasNext()
            { return _i.hasNext(); }

        public TResult next()
            { return select(_i.next()); }
    }

    protected abstract TResult select(TSource source);

    public Iterator<TResult> iterator()
        { return new Iter(); }
}

abstract class Where<TSource> implements Iterable<TSource>
{
    private Iterable<TSource> _source;

    public Where(Iterable<TSource> source)
        { _source = source; }

    private class Iter implements Iterator<TSource>
    {
        private Iterator<TSource> _i;
        private TSource _cachedNext;
        private boolean _hasCachedNext;

        public Iter()
        {
            _i = _source.iterator();
            fetch();
        }

        public void remove()
            { _i.remove(); }

        public boolean hasNext()
            { return _hasCachedNext; }

        public TSource next()
        {
            TSource result = _cachedNext;
            fetch();
            return result;
        }

        private void fetch()
        {
            _hasCachedNext = false;

            while (_i.hasNext())
            {
                _cachedNext = _i.next();
                if (predicate(_cachedNext))
                {
                    _hasCachedNext = true;
                    return;
                }
            }
        }
    }

    protected abstract boolean predicate(TSource source);

    public Iterator<TSource> iterator()
        { return new Iter(); }
}
+1

SBQL4J . Java-, 100% Java 6 VM. SBQL4J , LINQ-to-objects.

Examples of Daniel queries should look like this:

Vector<Integer> numbers = new Vector<Integer>();

numbers.add(42);
numbers.add(3);
numbers.add(16);
numbers.add(92);
numbers.add(9);

Iterable<Integer> filtered = #{ numbers as n where n > 10 };

Iterable<String> converted = #{ numbers.toString() };

for (final String str : converted)
    System.out.println(str);

There are about 35 query language operators, including selection, projection, ordering, arithmetic operators, aggregation, transitive closure, range, etc.

+1
source

There is a 166y add-on for JSR166y with ParallelArray . Basically PLINQ for arrays of objects.

0
source

All Articles