private static void companyBasedSalaryAverage(IMap<String, Employee> employees) { System.out.println("Calculating average monthly salary for Hazelcast"); // create the Predicate to select only Hazelcast employees Predicate<String, Employee> companyPredicate = new CompanyPredicate("Hazelcast"); // create the PropertyExtractor to extract salary value from the employee PropertyExtractor<Employee, Integer> propertyExtractor = new SalaryPropertyExtractor(); // create the supplier to handle extracted salaries from selected employees Supplier<String, Employee, Integer> salaryExtractor = Supplier.all(propertyExtractor); // merge Predicate and PropertyExtractor (through the previous Supplier) together Supplier<String, Employee, Integer> supplier = Supplier.fromPredicate(companyPredicate, salaryExtractor); // choose the aggregation to perform Aggregation<String, Integer, Integer> aggregation = Aggregations.integerAvg(); // execute the aggregation and print the result int avgSalary = employees.aggregate(supplier, aggregation); System.out.println("Hazelcast average salary: " + avgSalary); System.out.println("\n"); // in Java 8: //int avgSalary = employees.aggregate( // Supplier.fromPredicate( // (entry) -> "Hazelcast".equals(mapEntry.getValue().getCompanyName(), // Supplier.all((value) -> value.getSalaryPerMonth()) // ), Aggregations.integerAvg()); }