Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2010 the original author or authors.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package org.callbackparams.combine;
Abstract stub implementation of CombineStrategy that is intended to be a convenient super-class for most implementations.

Henrik Kaipe
public abstract class AbstractCombineStrategy implements CombineStrategy {
    protected int maxCount = .;
    private long randomSeed;
    private boolean randomSeedIsSet = false;
    public void setMaxCount(int maxCount) {
        this. = maxCount;
    public void setRandomSeed(long randomSeed) {
        this. = randomSeed;
        this. = true;
    public Collection combine(ValuesCollection vc) {
        final Collection records = combineInternal(vc);
        final int size = records.size();
        if ( < size || . == size) {
            throw new AssertionError("Number of callback records ("
                    + records.size() + ") exceeds the maximum number of "
                    + "callback records allowed (" +  + "). If you "
                    + "think the maximum number of callback records is too low "
                    + "you can change it by reconfiguring the 'maxCount' "
                    + "parameter");
        } else {
            return records;

Returns the random-seed that has been set by setRandomSeed(long). If random-seed has not yet been set it will be set to the current timestamp.
    protected long getRandomSeed() {
        if (false == ) {
             * By printing the generated random seed it will be documented and
             * could be reused in case the generated collection of
             * callback-records turns out the be of particular interest. (E.g.
             * by unexpectedly failing one of the tests.)
            ..println("Combine using random seed: " + );
        return ;

This is the method to implement when implementing CombineStrategy by subclassing AbstractCombineStrategy. The advantage compared to overriding combine(org.callbackparams.combine.ValuesCollection) is that maxCount-check and validation of configuration for setMaxCount(int) and setRandomSeed(long) will be taken care of by the super-class - relieving this method to administer combining exclusivly.
    protected abstract Collection combineInternal(ValuesCollection vc);
New to GrepCode? Check out our FAQ X