/** * Returns an aggregation to find the double maximum of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT MAX(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the maximum value over all supplied values */ public static <Key, Value> Aggregation<Key, Double, Double> doubleMax() { return new AggregationAdapter(new DoubleMaxAggregation<Key, Value>()); }
/** * Returns an aggregation to find the {@link java.math.BigInteger} maximum * of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT MAX(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the maximum value over all supplied values */ public static <Key, Value> Aggregation<Key, BigInteger, BigInteger> bigIntegerMax() { return new AggregationAdapter(new BigIntegerMaxAggregation<Key, Value>()); }
/** * Returns an aggregation to find the long minimum of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT MIN(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the minimum value over all supplied values */ public static <Key, Value> Aggregation<Key, Long, Long> longMin() { return new AggregationAdapter(new LongMinAggregation<Key, Value>()); }
/** * Returns an aggregation to find the {@link java.math.BigInteger} minimum * of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT MIN(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the minimum value over all supplied values */ public static <Key, Value> Aggregation<Key, BigInteger, BigInteger> bigIntegerMin() { return new AggregationAdapter(new BigIntegerMinAggregation<Key, Value>()); }
/** * Returns an aggregation for counting all supplied values.<br/> * This aggregation is similar to: <pre>SELECT COUNT(*) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the count of all supplied elements */ public static <Key, Value> Aggregation<Key, Value, Long> count() { return new AggregationAdapter(new CountAggregation<Key, Value>()); }
/** * Returns an aggregation to find the integer minimum of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT MIN(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the minimum value over all supplied values */ public static <Key, Value> Aggregation<Key, Integer, Integer> integerMin() { return new AggregationAdapter(new IntegerMinAggregation<Key, Value>()); }
/** * Returns an aggregation to find the minimum value of all supplied * {@link java.lang.Comparable} implementing values.<br/> * This aggregation is similar to: <pre>SELECT MIN(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the minimum value over all supplied values */ public static <Key, Value> Aggregation<Key, Comparable, Comparable> comparableMin() { return new AggregationAdapter(new ComparableMinAggregation<Key, Value>()); }
/** * Returns an aggregation to find the integer maximum of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT MAX(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the maximum value over all supplied values */ public static <Key, Value> Aggregation<Key, Integer, Integer> integerMax() { return new AggregationAdapter(new IntegerMaxAggregation<Key, Value>()); }
/** * Returns an aggregation to calculate the long average of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT AVG(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the average over all supplied values */ public static <Key, Value> Aggregation<Key, Long, Long> longAvg() { return new AggregationAdapter(new LongAvgAggregation<Key, Value>()); }
/** * Returns an aggregation to find the double minimum of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT MIN(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the minimum value over all supplied values */ public static <Key, Value> Aggregation<Key, Double, Double> doubleMin() { return new AggregationAdapter(new DoubleMinAggregation<Key, Value>()); }
/** * Returns an aggregation to find the {@link java.math.BigDecimal} minimum * of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT MIN(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the minimum value over all supplied values */ public static <Key, Value> Aggregation<Key, BigDecimal, BigDecimal> bigDecimalMin() { return new AggregationAdapter(new BigDecimalMinAggregation<Key, Value>()); }
/** * Returns an aggregation to find the maximum value of all supplied * {@link java.lang.Comparable} implementing values.<br/> * This aggregation is similar to: <pre>SELECT MAX(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the maximum value over all supplied values */ public static <Key, Value> Aggregation<Key, Comparable, Comparable> comparableMax() { return new AggregationAdapter(new ComparableMaxAggregation<Key, Value>()); }
/** * Returns an aggregation to calculate the integer average of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT AVG(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the average over all supplied values */ public static <Key, Value> Aggregation<Key, Value, Integer> integerAvg() { return new AggregationAdapter(new IntegerAvgAggregation<Key, Value>()); }
/** * Returns an aggregation to calculate the long sum of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT SUM(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the sum over all supplied values */ public static <Key, Value> Aggregation<Key, Long, Long> longSum() { return new AggregationAdapter(new LongSumAggregation<Key, Value>()); }
/** * Returns an aggregation to calculate the double sum of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT SUM(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the sum over all supplied values */ public static <Key, Value> Aggregation<Key, Double, Double> doubleSum() { return new AggregationAdapter(new DoubleSumAggregation<Key, Value>()); }
private static void salarySum(IMap<String, Employee> employees) { // create the PropertyExtractor to extract salary value from the employee PropertyExtractor<Employee, Integer> propertyExtractor = new SalaryPropertyExtractor(); // select all employees Supplier<String, Employee, Integer> supplier = Supplier.all(propertyExtractor); // choose the aggregation to perform Aggregation<String, Integer, Integer> aggregation = Aggregations.integerSum(); // execute the aggregation and print the result int sumSalary = employees.aggregate(supplier, aggregation); System.out.println("Sum of all salaries: " + sumSalary); System.out.println("\n"); // in Java 8: //int sumSalary = employees.aggregate(Supplier.all((value) -> value.getSalaryPerMonth()), Aggregations.integerSum()); }
private static void countEmployees(IMap<String, Employee> employees) { // select all employees Supplier<String, Employee, Object> supplier = Supplier.all(); // choose the aggregation to perform Aggregation<String, Object, Long> aggregation = Aggregations.count(); // execute the aggregation and print the result long countEmployee = employees.aggregate(supplier, aggregation); System.out.println("Number of employees: " + countEmployee); System.out.println("\n"); // in Java 8: //long countEmployees = employees.aggregate(Supplier.all(), Aggregations.count()); }
@Override public ValueOut apply(Map.Entry<KeyIn, ValueIn> entry) { ValueIn value = entry.getValue(); return propertyExtractor != null ? propertyExtractor.extract(value) : (ValueOut) value; }
/** * Returns an aggregation to find the double maximum of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT MAX(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the maximum value over all supplied values */ public static <Key, Value> Aggregation<Key, Double, Double> doubleMax() { return new AggregationAdapter(new DoubleMaxAggregation<Key, Value>()); }
/** * Returns an aggregation to find the {@link java.math.BigInteger} maximum * of all supplied values.<br/> * This aggregation is similar to: <pre>SELECT MAX(value) FROM x</pre> * * @param <Key> the input key type * @param <Value> the supplied value type * @return the maximum value over all supplied values */ public static <Key, Value> Aggregation<Key, BigInteger, BigInteger> bigIntegerMax() { return new AggregationAdapter(new BigIntegerMaxAggregation<Key, Value>()); }