package com.onaro.sanscreen.client.view.common.functions; import java.lang.reflect.InvocationTargetException; import java.util.Collection; import java.util.List; import java.util.Map; import org.eclipse.core.runtime.IAdaptable; import com.onaro.client.leekui.runtime.OnaroAdapterUtils; import com.onaro.commons.lang.OnaroThreadUtils; import com.onaro.sanscreen.server.interfaces.data.IDataObjectType; /** * BulkFunction implementation that handles input objects with different {@link IDataObjectType}s. * The implementation will classify the input objects based on their IDataObjectType, and pass the * sets with the same IDataObjectType on to its subclass for evaluation. * To work properly, the input objects must be a subclass of {@link IAdaptable), and support being adapted to IDataObjectType. * * @param IAdaptable row type this Function is able to operate on. Should allow adapting to IDataObjectType. * @param data type returned by this Function * * @see IAdaptable * @see IDataObjectType */ public abstract class AbstractDataObjectTypeAwareBulkFunction extends AbstractRefreshableBulkFunction { public AbstractDataObjectTypeAwareBulkFunction() { super(); } public AbstractDataObjectTypeAwareBulkFunction(boolean isMainView) { super(isMainView); } public void evaluate(Collection inputs, Map outputMap) throws InterruptedException, InvocationTargetException { Map> dataObjectTypesToAdaptablesMap = OnaroAdapterUtils.indexByAdapter(inputs, IDataObjectType.class); for (Map.Entry> mapEntry : dataObjectTypesToAdaptablesMap.entrySet()) { OnaroThreadUtils.checkInterrupted(); IDataObjectType dataObjectType = mapEntry.getKey(); List inputsWithSameContext = mapEntry.getValue(); evaluate(inputsWithSameContext, dataObjectType, outputMap); } } /** * Evaluate the bulk function on all of the given rows. The results of the call should be placed in the * output map, with each input row having a corresponding data entry in the output. * * @param inputs The IAdaptable inputs all with the same data object type. * @param dataObjectType the IDataObjectType which all the inputs share. * @param outputMap The output of the function, a correspondence between the input row, and the result * of the evaluation of that row. * @throws InterruptedException Calls to this function should be interruptible, and throw this when interrupted. */ protected abstract void evaluate(Collection inputs, IDataObjectType dataObjectType, Map outputMap) throws InterruptedException, InvocationTargetException; }