@@ -0,0 +1,3228 @@
+package weatherhandler.processor.query;%0A%0Aimport java.io.OutputStream;%0Aimport java.io.PrintStream;%0Aimport java.util.Map;%0Aimport java.util.HashMap;%0Aimport java.util.function.Function;%0Aimport java.util.function.ToDoubleFunction;%0Aimport java.lang.AutoCloseable;%0A%0Aimport weatherhandler.data.Measurement;%0Aimport weatherhandler.Logger;%0A%0A/**%0A * @author Marijn Pool%0A * @author Ren%C3%A9 Kooi%0A *%0A * Query class for computing the lowest value by some grouping. Output is sent%0A * to an OutputStream in TSV format.%0A */%0Apublic class MinQuery%3CT%3E extends NumericGroupedQuery%3CT%3E implements AutoCloseable %7B%0A    /**%0A     * Used by NumericGroupedQuery for logging (potentially).%0A     */%0A    protected Logger logger = new Logger(%22MinQuery%22);%0A%0A    /**%0A     * Create a new MinQuery, directing output to the given output stream.%0A     *%0A     * @param out Output stream.%0A     * @param grouper Function that returns a group key for a given measurement.%0A     * @param mapper Function that returns the number to use for the min()%0A     *               computation.%0A     */%0A    public MinQuery(%0A        OutputStream out,%0A        Function%3CMeasurement, T%3E grouper,%0A        ToDoubleFunction%3CMeasurement%3E mapper%0A    ) %7B%0A        super(out, grouper, mapper);%0A    %7D%0A%0A    /**%0A     * Create a new MinQuery, directing output to standard output.%0A     *%0A     * @param out Output stream.%0A     * @param grouper Function that returns a group key for a given measurement.%0A     * @param mapper Function that returns the number to use for the min()%0A     *               computation.%0A     */%0A    public MinQuery(%0A        Function%3CMeasurement, T%3E grouper,%0A        ToDoubleFunction%3CMeasurement%3E mapper%0A    ) %7B%0A        super(grouper, mapper);%0A    %7D%0A%0A    /**%0A     * @return Query that computes the lowest temperature ever measured.%0A     */%0A    public static MinQuery%3CInteger%3E temperature() %7B%0A        return new MinQuery%3CInteger%3E(%0A            m -%3E 1,%0A            Measurement::getTemperature%0A        );%0A    %7D%0A%0A    /**%0A     * Create a new query group.%0A     *%0A     * @return Query group that returns the lowest value in the given numbers.%0A     */%0A    protected Minimum newGroup() %7B%0A        return new Minimum();%0A    %7D%0A%0A    /**%0A     * Print the result set to a file or stream in TSV format.%0A     */%0A    public void close() %7B%0A        this.output.println(%22group_key%5Ctminimum%22);%0A        for (T group : groups.keySet()) %7B%0A            this.output.println(%0A                String.join(%22%5Ct%22, new String%5B%5D %7B%0A                    %22%22 + group,%0A                    %22%22 + groups.get(group).get()%0A                %7D)%0A            );%0A        %7D%0A    %7D%0A%0A    /**%0A     * Group class for computing minima.%0A     */%0A    protected class Minimum implements NumericGroupedQuery.Group %7B%0A        /**%0A         * Lowest number seen so far.%0A         */%0A        private double min = 0;%0A%0A        /**%0A         * Check a new contestant for the title of %22Lowest Number Known To This%0A         * Group%22.%0A         *%0A         * @param n The daring new contestant.%0A         */%0A        public void add(double n) %7B%0A            if (n %3C min) %7B%0A                min = n;%0A            %7D%0A        %7D%0A%0A        /**%0A         * @return The lowest value in this group.%0A         */%0A        public double get() %7B%0A            return min;%0A        %7D%0A    %7D%0A%7D%0A

Add query for computing minima