001/*
002 * Copyright (c) 2016-2017 Chris K Wensel <chris@wensel.net>. All Rights Reserved.
003 * Copyright (c) 2007-2017 Xplenty, Inc. All Rights Reserved.
004 *
005 * Project and contact information: http://www.cascading.org/
006 *
007 * This file is part of the Cascading project.
008 *
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *     http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 */
021
022package cascading.operation;
023
024import cascading.flow.FlowProcess;
025import cascading.tuple.TupleEntry;
026
027/**
028 * Class GroupAssertion is a kind of {@link Assertion} used with the {@link cascading.pipe.Every} pipe Operator.
029 * <p>
030 * Implementers should also extend {@link BaseOperation}.
031 *
032 * @see Aggregator
033 */
034public interface GroupAssertion<C> extends Assertion<C>
035  {
036  /**
037   * Method start initializes the aggregation procedure and is called for every unique grouping.
038   * <p>
039   * The AggregatorCall context should be initialized here if necessary.
040   * <p>
041   * The first time this method is called for a given 'process', the AggregatorCall context will be null. This method should
042   * set a new instance of the user defined context object. When the AggregatorCall context is not null, it is up to
043   * the developer to create a new instance, or 'recycle' the given instance. If recycled, it must be re-initialized to
044   * remove any previous state/values.
045   * <p>
046   * For example, if a Map is used to hold the intermediate data for each subsequent
047   * {@link #aggregate(cascading.flow.FlowProcess, GroupAssertionCall)} call,
048   * new HashMap() should be set on the AggregatorCall instance when {@link cascading.operation.AggregatorCall#getContext()} is null.
049   * On the next grouping, start() will be called again, but this time with the old Map instance. In this case,
050   * map.clear() should be invoked before returning.
051   *
052   * @param flowProcess   of type FlowProcess
053   * @param assertionCall of type GroupAssertionCall
054   */
055  void start( FlowProcess flowProcess, GroupAssertionCall<C> assertionCall );
056
057  /**
058   * Method aggregate is called for each {@link TupleEntry} value in the current grouping.
059   *
060   * @param flowProcess   of type FlowProcess
061   * @param assertionCall of type GroupAssertionCall
062   */
063  void aggregate( FlowProcess flowProcess, GroupAssertionCall<C> assertionCall );
064
065  /**
066   * Method doAssert performs the assertion.
067   *
068   * @param flowProcess   of type FlowProcess
069   * @param assertionCall of type GroupAssertionCall
070   */
071  void doAssert( FlowProcess flowProcess, GroupAssertionCall<C> assertionCall );
072
073  }