From 8c705eef1cb8e34a38be58a03d631d1201599345 Mon Sep 17 00:00:00 2001 From: GCHQDev404 Date: Mon, 17 May 2021 04:06:34 -0700 Subject: [PATCH] gh-2425 remove duplicate updateOperationInput --- .../graph/hook/NamedOperationResolver.java | 17 ++----------- .../handler/OperationChainHandler.java | 25 ++----------------- .../handler/util/OperationHandlerUtil.java | 6 ++--- 3 files changed, 7 insertions(+), 41 deletions(-) diff --git a/core/graph/src/main/java/uk/gov/gchq/gaffer/graph/hook/NamedOperationResolver.java b/core/graph/src/main/java/uk/gov/gchq/gaffer/graph/hook/NamedOperationResolver.java index 5f19bccc996..dd36c2851d9 100644 --- a/core/graph/src/main/java/uk/gov/gchq/gaffer/graph/hook/NamedOperationResolver.java +++ b/core/graph/src/main/java/uk/gov/gchq/gaffer/graph/hook/NamedOperationResolver.java @@ -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; @@ -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. */ @@ -94,18 +95,4 @@ private List 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); - } - } } diff --git a/core/store/src/main/java/uk/gov/gchq/gaffer/store/operation/handler/OperationChainHandler.java b/core/store/src/main/java/uk/gov/gchq/gaffer/store/operation/handler/OperationChainHandler.java index 56956e2c07e..6155c4ac7e8 100644 --- a/core/store/src/main/java/uk/gov/gchq/gaffer/store/operation/handler/OperationChainHandler.java +++ b/core/store/src/main/java/uk/gov/gchq/gaffer/store/operation/handler/OperationChainHandler.java @@ -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; @@ -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. * @@ -65,33 +66,11 @@ public OperationChain prepareOperationChain(final OperationChain 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 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; } diff --git a/core/store/src/main/java/uk/gov/gchq/gaffer/store/operation/handler/util/OperationHandlerUtil.java b/core/store/src/main/java/uk/gov/gchq/gaffer/store/operation/handler/util/OperationHandlerUtil.java index 2d56b661d5b..3ac5d4018ba 100644 --- a/core/store/src/main/java/uk/gov/gchq/gaffer/store/operation/handler/util/OperationHandlerUtil.java +++ b/core/store/src/main/java/uk/gov/gchq/gaffer/store/operation/handler/util/OperationHandlerUtil.java @@ -53,17 +53,17 @@ public static void updateOperationInput(final Operation operation, final Object final Operation firstOp = (Operation) ((OperationChain) operation).getOperations().get(0); //TODO_ticket This if statement can be removed with recursion. 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); }