What is the best way to filter a Java Collection?

后端 未结 27 3422
故里飘歌
故里飘歌 2020-11-21 06:55

I want to filter a java.util.Collection based on a predicate.

27条回答
  •  我寻月下人不归
    2020-11-21 07:33

    JFilter http://code.google.com/p/jfilter/ is best suited for your requirement.

    JFilter is a simple and high performance open source library to query collection of Java beans.

    Key features

    • Support of collection (java.util.Collection, java.util.Map and Array) properties.
    • Support of collection inside collection of any depth.
    • Support of inner queries.
    • Support of parameterized queries.
    • Can filter 1 million records in few 100 ms.
    • Filter ( query) is given in simple json format, it is like Mangodb queries. Following are some examples.
    • { "id":{"$le":"10"}
      • where object id property is less than equals to 10.
    • { "id": {"$in":["0", "100"]}}
      • where object id property is 0 or 100.
    • {"lineItems":{"lineAmount":"1"}}
      • where lineItems collection property of parameterized type has lineAmount equals to 1.
    • { "$and":[{"id": "0"}, {"billingAddress":{"city":"DEL"}}]}
      • where id property is 0 and billingAddress.city property is DEL.
    • {"lineItems":{"taxes":{ "key":{"code":"GST"}, "value":{"$gt": "1.01"}}}}
      • where lineItems collection property of parameterized type which has taxes map type property of parameteriszed type has code equals to GST value greater than 1.01.
    • {'$or':[{'code':'10'},{'skus': {'$and':[{'price':{'$in':['20', '40']}}, {'code':'RedApple'}]}}]}
      • Select all products where product code is 10 or sku price in 20 and 40 and sku code is "RedApple".

提交回复
热议问题