簡體   English   中英

用於查詢集合/對象的Java庫

[英]Java Library to query Collections/Objects

我正在尋找允許我查詢集合的Java庫。 我偶然發現了jFilterJoSql

但是,似乎JoSql自2010年以來一直處於非活動狀態,並且只有2個版本。 jFilter似乎相當新,自去年以來沒有任何新版本。

當谷歌搜索其中任何一個時,搜索結果的數量很少,這表明他們並沒有被廣泛使用。

您對這些庫有什么建議,或者知道更活躍一次嗎?

我在公司成功使用了CqEngine( https://code.google.com/p/cqengine/

實例化集合時,可以輕松定義一組索引。 這比謂詞強大得多。

此外,當您對集合執行搜索時,CqEngine將不會迭代整個集合,然后檢查每條記錄是否與謂詞匹配。 相反,它將直接在Map中找到匹配的記錄,如數據結構。 因此,你將有出色的表現。

您可以查看Commons Collections ,更具體地說是CollectionUtils.filter(Collection, Filter)

另一種選擇是Google Guava ,它有Iterables.filter(Iterable<T>, Predicate<? super T>)

這是你的選擇。

可能是為時已晚,但對其他人可能有幫助,你可以使用,

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

它支持以下語法,

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;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM