Created
October 13, 2015 17:36
-
-
Save enesakar/2db530e8a38890578172 to your computer and use it in GitHub Desktop.
hazelcast aggregation count with filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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