001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.functor.aggregator; 018 019import org.apache.commons.functor.NullaryFunction; 020 021/** 022 * Interface which offers a means of "aggregating" data. It offers functions 023 * which allows for data to be added to a "series" and then aggregate them. The 024 * term "aggregation" is possibly a bit loose here as this interface doesn't 025 * enforce summing up or averaging or any other way of processing the data -- it 026 * simply allows for the values to be processed in such a way that it generates 027 * a result. The aggregation of data will be done in the <code>evaluate()</code> 028 * function. This is the function at the core of the aggregator package as it 029 * allows for a way to process the data series and get a result of the same type 030 * out of this operation. Note that some aggregators will compute the data at 031 * this point by iterating through the series of data previously stored (if any) 032 * while others might prefer to compute this value on the fly, every time 033 * {@link #add(Object)} is called. This interface doesn't make any assumption as 034 * to when the aggregation result should be computed. 035 * 036 * @param <T> 037 * type of data to aggregate 038 */ 039public interface Aggregator<T> extends NullaryFunction<T> { 040 /** 041 * Adds data to the series which will be aggregated. It doesn't enforce any 042 * limitations on how much data can be stored (or in fact whether it should 043 * be stored) nor does it make any assumptions on synchronization. 044 * 045 * @param data 046 * Data to be added to the series which this aggregator will 047 * process/aggregate. 048 */ 049 void add(T data); 050 051 /** 052 * Resets any series of data previously stored and returns the aggregator in 053 * the initial state. 054 */ 055 void reset(); 056}