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 java.util.Map.Entry; import org.eclipse.core.runtime.IAdaptable; import com.onaro.client.leekui.runtime.OnaroAdapterUtils; import com.onaro.sanscreen.server.interfaces.data.Context; import com.onaro.sanscreen.server.interfaces.data.IDataObjectType; /** * BulkFunction implementation that handles input objects with different {@link Context}s and different {@link IDataObjectType}s. * The implementation will classify the input objects based on their Context and IDataObjectType, and pass the * sets with the same Context and 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 Context and * IDataObjectType. * * @param IAdaptable row type this Function is able to operate on. Should allow adapting to Context and IDataObjectType. * @param data type returned by this Function * * @see IAdaptable * @see Context * @see IDataObjectType */ public abstract class AbstractDataObjectTypeAndContextAwareBulkFunction extends AbstractContextAwareBulkFunction { public AbstractDataObjectTypeAndContextAwareBulkFunction() { super(); } public AbstractDataObjectTypeAndContextAwareBulkFunction(boolean isMainView) { super(isMainView); } @Override protected void evaluate(Collection inputs, Context context, Map outputMap) throws InterruptedException, InvocationTargetException { Map> dataObjectTypeToInputsMap = OnaroAdapterUtils.indexByAdapter(inputs, IDataObjectType.class); for (Entry> mapEntry : dataObjectTypeToInputsMap.entrySet()) { IDataObjectType dataObjectType = mapEntry.getKey(); List inputsWithSameClassAndContext = mapEntry.getValue(); evaluate(inputsWithSameClassAndContext, dataObjectType, context, 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 context and data object type. * @param dataObjectType the IDataObjectType which all the inputs share. * @param context the Context 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, Context context, Map outputMap) throws InterruptedException, InvocationTargetException; }