FileDocCategorySizeDatePackage
ArgumentReplacingDispatcher.javaAPI DocAndroid 5.1 API3449Thu Mar 12 22:22:10 GMT 2015android.hardware.camera2.dispatch

ArgumentReplacingDispatcher

public class ArgumentReplacingDispatcher extends Object implements Dispatchable
A dispatcher that replaces one argument with another; replaces any argument at an index with another argument.

For example, we can override an {@code void onSomething(int x)} calls to have {@code x} always equal to 1. Or, if using this with a duck typing dispatcher, we could even overwrite {@code x} to be something that's not an {@code int}.

param
source dispatch type, whose methods with {@link #dispatch} will be called
param
argument replacement type, args in {@link #dispatch} matching {@code argumentIndex} will be overriden to objects of this type

Fields Summary
private final Dispatchable
mTarget
private final int
mArgumentIndex
private final TArg
mReplaceWith
Constructors Summary
public ArgumentReplacingDispatcher(Dispatchable target, int argumentIndex, TArg replaceWith)
Create a new argument replacing dispatcher; dispatches are forwarded to {@code target} after the argument is replaced.

For example, if a method {@code onAction(T1 a, Integer b, T2 c)} is invoked, and we wanted to replace all occurrences of {@code b} with {@code 0xDEADBEEF}, we would set {@code argumentIndex = 1} and {@code replaceWith = 0xDEADBEEF}.

If a method dispatched has less arguments than {@code argumentIndex}, it is passed through with the arguments unchanged.

param
target destination dispatch type, methods will be redirected to this dispatcher
param
argumentIndex the numeric index of the argument {@code >= 0}
param
replaceWith arguments matching {@code argumentIndex} will be replaced with this object

        mTarget = checkNotNull(target, "target must not be null");
        mArgumentIndex = checkArgumentNonnegative(argumentIndex,
                "argumentIndex must not be negative");
        mReplaceWith = checkNotNull(replaceWith, "replaceWith must not be null");
    
Methods Summary
private static java.lang.Object[]arrayCopy(java.lang.Object[] array)

        int length = array.length;
        Object[] newArray = new Object[length];
        for (int i = 0; i < length; ++i) {
            newArray[i] = array[i];
        }
        return newArray;
    
public java.lang.Objectdispatch(java.lang.reflect.Method method, java.lang.Object[] args)


        if (args.length > mArgumentIndex) {
            args = arrayCopy(args); // don't change in-place since it can affect upstream dispatches
            args[mArgumentIndex] = mReplaceWith;
        }

        return mTarget.dispatch(method, args);