在Java中对Hazelcast的JSON值进行排序。

huangapple go评论85阅读模式
英文:

Sort the Hazelcast json value in java

问题

我将Hazelcast JSON值存储在IMAP中

IMap.put(Integer, new HazelcastjsonValue("{\"id\":\"001\",\"name\":\"vikram\"}"));
IMap.put(Integer, new HazelcastjsonValue("{\"id\":\"002\",\"name\":\"abhishek\"}"));

如何按name对HazelcastjsonValue进行排序

我知道我们可以使用分页谓词来实现排序的JSON数组。

但如何为HazelcastjsonValue使用分页谓词。

有谁可以帮我解决这个问题吗?

英文:

I'm storing the Hazelcast JSON value in IMAP

IMap.put(Integer,new HazelcastjsonValue("{"id":"001","name":"vikram"}"));
IMap.put(Integer,new HazelcastjsonValue("{"id":"002","name":"abhishek"}"));

How to sort the HazelcastjsonValue by name

I know using paging predicate we can achieve a sorted JSON array.

But how to use the paging predicate for the HazelcastjsonValue.

Can anyone please help me with this?

答案1

得分: -1

你可以按照Hazelcast参考手册:索引查询中的描述设置索引。在你的情况下,代码如下:

IMap.addIndex(new IndexConfig(IndexType.SORTED, "name"));

然后,结果集合应该是有序的。

如果你不想设置索引,那么我猜你可以使用Predicates.pagingPredicate(comparator, size),但是你需要编写自己的自定义比较器。

英文:

You can set an index as described in Hazelcast Reference Manual: Indexing Queries. In your case, it would look like:

IMap.addIndex(new IndexConfig(IndexType.SORTED, "name"));

Then, the result collection should be sorted.

If you don't want to set an index, then I guess you can use Predicates.pagingPredicate(comparator, size), but you would need write your own custom comparator.

huangapple
  • 本文由 发表于 2020年10月7日 18:32:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/64242232.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定