Skip to content

Instantly share code, notes, and snippets.

@enesakar
Created October 13, 2015 17:36
Show Gist options
  • Select an option

  • Save enesakar/2db530e8a38890578172 to your computer and use it in GitHub Desktop.

Select an option

Save enesakar/2db530e8a38890578172 to your computer and use it in GitHub Desktop.
hazelcast aggregation count with filter
public static void main(String[] args) throws InterruptedException {
HazelcastInstance instance = Hazelcast.newHazelcastInstance(new Config());
IMap<Integer, Person> map = instance.getMap("map");
for (int i = 0; i < 100; i++) {
map.put(i, new Person("name" + i, i % 10));
}
Supplier supplier = Supplier.all(new AgeExtractor(5));
Aggregation aggregation = Aggregations.count();
Long count = (Long) map.aggregate(supplier, aggregation);
System.out.println("count:"+count);
}
static class AgeExtractor implements PropertyExtractor<Person, Integer>, Serializable {
int filter;
AgeExtractor(int age) {
this.filter = age;
}
public Integer extract(Person value) {
if(value.age == filter) {
return value.age;
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment