Skip to content

Commit

Permalink
gh-2425 remove duplicate updateOperationInput
Browse files Browse the repository at this point in the history
  • Loading branch information
GCHQDev404 committed May 17, 2021
1 parent 3869278 commit 099965f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import uk.gov.gchq.gaffer.operation.Operation;
import uk.gov.gchq.gaffer.operation.OperationChain;
import uk.gov.gchq.gaffer.operation.Operations;
import uk.gov.gchq.gaffer.operation.io.Input;
import uk.gov.gchq.gaffer.store.Context;
import uk.gov.gchq.gaffer.store.operation.handler.named.cache.NamedOperationCache;
import uk.gov.gchq.gaffer.user.User;
Expand All @@ -33,6 +32,8 @@
import java.util.Collections;
import java.util.List;

import static uk.gov.gchq.gaffer.store.operation.handler.util.OperationHandlerUtil.updateOperationInput;

/**
* A {@link GraphHook} to resolve named operations.
*/
Expand Down Expand Up @@ -94,18 +95,4 @@ private List<Operation> resolveNamedOperation(final NamedOperation namedOp, fina
resolveNamedOperations(namedOperationChain, user);
return namedOperationChain.getOperations();
}

/**
* Injects the input of the NamedOperation into the first operation in the OperationChain. This is used when
* chaining NamedOperations together.
*
* @param opChain the resolved operation chain
* @param input the input of the NamedOperation
*/
private void updateOperationInput(final OperationChain<?> opChain, final Object input) {
final Operation firstOp = opChain.getOperations().get(0);
if (null != input && (firstOp instanceof Input) && null == ((Input) firstOp).getInput()) {
((Input) firstOp).setInput(input);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import uk.gov.gchq.gaffer.operation.Operation;
import uk.gov.gchq.gaffer.operation.OperationChain;
import uk.gov.gchq.gaffer.operation.OperationException;
import uk.gov.gchq.gaffer.operation.io.Input;
import uk.gov.gchq.gaffer.store.Context;
import uk.gov.gchq.gaffer.store.Store;
import uk.gov.gchq.gaffer.store.operation.OperationChainValidator;
Expand All @@ -27,6 +26,8 @@

import java.util.List;

import static uk.gov.gchq.gaffer.store.operation.handler.util.OperationHandlerUtil.updateOperationInput;

/**
* A {@code OperationChainHandler} handles {@link OperationChain}s.
*
Expand Down Expand Up @@ -65,33 +66,11 @@ public <O> OperationChain<O> prepareOperationChain(final OperationChain<O> opera
return optimisedOperationChain;
}

protected void updateOperationInput(final Operation op, final Object result) {
if (null != result) {
if (op instanceof OperationChain) {
if (!((OperationChain) op).getOperations().isEmpty()) {
final Operation firstOp = (Operation) ((OperationChain) op).getOperations()
.get(0);
if (firstOp instanceof Input) {
setOperationInput(firstOp, result);
}
}
} else if (op instanceof Input) {
setOperationInput(op, result);
}
}
}

public OperationChainHandler(final OperationChainValidator opChainValidator, final List<OperationChainOptimiser> opChainOptimisers) {
this.opChainValidator = opChainValidator;
this.opChainOptimisers = opChainOptimisers;
}

private void setOperationInput(final Operation op, final Object result) {
if (null == ((Input) op).getInput()) {
((Input) op).setInput(result);
}
}

protected OperationChainValidator getOpChainValidator() {
return opChainValidator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ public static void updateOperationInput(final Operation operation, final Object
if (!((OperationChain) operation).getOperations().isEmpty()) {
final Operation firstOp = (Operation) ((OperationChain) operation).getOperations().get(0);
if (firstOp instanceof Input) {
setOperationInput((Input) firstOp, input);
setOperationInputIfNull((Input) firstOp, input);
} else if (firstOp instanceof OperationChain) {
updateOperationInput(firstOp, input);
}
}
} else if (operation instanceof Input) {
setOperationInput((Input) operation, input);
setOperationInputIfNull((Input) operation, input);
}
}

private static void setOperationInput(final Input operation, final Object input) {
private static void setOperationInputIfNull(final Input operation, final Object input) {
if (null == operation.getInput()) {
operation.setInput(input);
}
Expand Down

0 comments on commit 099965f

Please sign in to comment.