All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.micro.testcases.multiinvoke.SumMultiplexCollector Maven / Gradle / Ivy

Go to download

The Jadex micro applications package contains several example applications, benchmarks and testcases using micro agents.

There is a newer version: 4.0.267
Show newest version
package jadex.micro.testcases.multiinvoke;

import java.util.ArrayList;
import java.util.List;

import jadex.bridge.service.component.multiinvoke.FlattenMultiplexCollector;
import jadex.commons.future.IntermediateFuture;

/**
 * 
 */
public class SumMultiplexCollector extends FlattenMultiplexCollector
{
	/** The list of results (if ret is not intermediate future). */
	protected List results = new ArrayList();
	
	/**
	 *  Add a result.
	 *  @param result The result.
	 */
	protected void addResult(Object result)
	{
		results.add(result);
	}
	
	/**
	 *  Set finished.
	 */
	protected void setFinished()
	{
		int sum = 0;
		for(Object res: results)
		{
			sum += ((Number)res).intValue();
		}
		
		if(fut instanceof IntermediateFuture)
		{
			((IntermediateFuture)fut).addIntermediateResult(Integer.valueOf(sum));
			((IntermediateFuture)fut).setFinished();
		}
		else
		{
			fut.setResult(Integer.valueOf(sum));
		}
	}
}