/* // $Id: //guest/julian_hyde/saffron/src/main/saffron/AggregatorExtender.java#1 $ // Saffron preprocessor and data engine // Copyright (C) 2002 Julian Hyde <julian.hyde@mail.com> // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Library General Public License for more details. // // You should have received a copy of the GNU Library General Public // License along with this library; if not, write to the // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // See the COPYING file located in the top-level-directory of // the archive of this library for complete text of license. */ package saffron; /** * An <code>AggregatorExtender</code> allows end-users to define their own * aggregate functions. * * <p> An aggregator extenders supports one or more sets of argument types, * <i>T</i>. <i>T</i> can be a single type (such as {@link String} or * <code>int</code>), several types (such as <code>String, int</code>), or * empty. For each set <i>T</i>, it declares 4 methods:<ul>x * * <li><code>Object start(T dummy)</code> creates an accumulator</li> * <li><code>void next(T dummy, Object accumulator)</code> adds a value to an * accumulator</li> * <li><code>void merge(T dummy, Object accumulator0, Object * accumulator1)</code> merges the contents of <code>accumulator1</code> * into <code>accumulator0</code></li> * <li><code>T2 result(T dummy, Object accumulator)</code> retrieves the result * from an accumulator</li></ul> * * (The <code>merge</code> method is actually optional. If it is not present, * {@link ExtenderAggregation#canMerge} returns <code>false</code>.) * * <p> Consider the query <blockquote> * * <pre>{@link java.util.Locale} locale = Locale.getDefault(); * {@link java.text.Collator} collator = Collator.getInstance(locale); * LocaleMin localeMin = new LocaleMin(collator); * select {localeMin.aggregate(emp.name)} * group by {emp.deptno} * from emps as emp</pre></blockquote> * * <p> Here <i>T</i> is <code>String</code>, and so {@link * LocaleMin#start(String)} will be called when a group starts, {@link * LocaleMin#next(String,Object)} on each row, and so forth. * * <p> Note that the aggregator object is evaluated <em>each time a group * starts</em>. If each department has its own locale, one could * write<blockquote> * * <pre>select {new LocaleMin(Collator.getInstance(emp.dept.locale)) * .aggregate(emp.name) } * group by {emp.dept} * from emps as emp</pre></blockquote> * * @author jhyde * @since 26 January, 2001 * @version $Id: //guest/julian_hyde/saffron/src/main/saffron/AggregatorExtender.java#1 $ **/ public interface AggregatorExtender { } // End AggregatorExtender.java
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 1474 | Julian Hyde |
saffron: Aggregations are working. Renamed 'aggregator' to 'aggregation'. |
||
#1 | 1467 | Julian Hyde |
saffron: First saffron check-in; incorporate my changes to openjava. |