From e78811eaa9674fca0a476e874fb5ec1c904df29f Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Sun, 13 Sep 2020 14:29:02 +0100 Subject: [PATCH] Remove Function interface - Switch from org.springframework.statemachine.support.Function to java.util.function.Function. - Fixes #867 --- ...ractPersistingStateMachineInterceptor.java | 2 +- .../support/AbstractStateMachine.java | 24 ++++++------- .../statemachine/support/Function.java | 35 ------------------- .../support/StateMachineUtils.java | 3 +- 4 files changed, 15 insertions(+), 49 deletions(-) delete mode 100644 spring-statemachine-core/src/main/java/org/springframework/statemachine/support/Function.java diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/persist/AbstractPersistingStateMachineInterceptor.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/persist/AbstractPersistingStateMachineInterceptor.java index 6d59a31b..1ca35add 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/persist/AbstractPersistingStateMachineInterceptor.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/persist/AbstractPersistingStateMachineInterceptor.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -37,7 +38,6 @@ import org.springframework.statemachine.state.State; import org.springframework.statemachine.support.AbstractStateMachine; import org.springframework.statemachine.support.DefaultExtendedState; import org.springframework.statemachine.support.DefaultStateMachineContext; -import org.springframework.statemachine.support.Function; import org.springframework.statemachine.support.StateMachineInterceptor; import org.springframework.statemachine.support.StateMachineInterceptorAdapter; import org.springframework.statemachine.transition.Transition; diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/support/AbstractStateMachine.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/support/AbstractStateMachine.java index 20d397f3..b585254a 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/support/AbstractStateMachine.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/support/AbstractStateMachine.java @@ -1074,7 +1074,7 @@ public abstract class AbstractStateMachine extends StateMachineObjectSuppo private Mono setCurrentStateInternal3(State state, Message message, Transition transition, boolean exit, StateMachine stateMachine, Collection> sources, Collection> targets) { - java.util.function.Function, State> mapFromTargetSub = in -> { + Function, State> mapFromTargetSub = in -> { if (transition != null) { boolean isTargetSubOf = StateMachineUtils.isSubstate(state, transition.getSource()); if (isTargetSubOf && currentState == transition.getTarget()) { @@ -1084,7 +1084,7 @@ public abstract class AbstractStateMachine extends StateMachineObjectSuppo return in; }; - java.util.function.Function, ? extends Mono>> handleExit = in -> { + Function, ? extends Mono>> handleExit = in -> { if (exit) { return exitCurrentState(in, message, transition, stateMachine, sources, targets) .then(Mono.just(in)) @@ -1093,14 +1093,14 @@ public abstract class AbstractStateMachine extends StateMachineObjectSuppo return Mono.just(in); }; - java.util.function.Function, ? extends Mono>> handleStart = in -> { + Function, ? extends Mono>> handleStart = in -> { if (!isRunning() && !isComplete()) { return startReactively().then(Mono.just(in)); } return Mono.just(in); }; - java.util.function.Function, ? extends Mono>> handleEntry1 = in -> { + Function, ? extends Mono>> handleEntry1 = in -> { State notifyFrom = currentState; currentState = in; return entryToState(in, message, transition, stateMachine) @@ -1112,7 +1112,7 @@ public abstract class AbstractStateMachine extends StateMachineObjectSuppo }); }; - java.util.function.Function, ? extends Mono>> handleEntry2 = in -> { + Function, ? extends Mono>> handleEntry2 = in -> { State notifyFrom = currentState; State findDeep = findDeepParent(in); currentState = findDeep; @@ -1125,14 +1125,14 @@ public abstract class AbstractStateMachine extends StateMachineObjectSuppo }); }; - java.util.function.Function, ? extends Mono>> handleStop = s -> { + Function, ? extends Mono>> handleStop = s -> { if (stateMachine != this && isComplete()) { return stopReactively().then(Mono.just(s)); } return Mono.just(s); }; - java.util.function.Function, ? extends Mono>> handleSubmachineOrRegions = in -> { + Function, ? extends Mono>> handleSubmachineOrRegions = in -> { return Mono.just(in) .flatMap(s -> { if (currentState == findDeepParent(s)) { @@ -1197,7 +1197,7 @@ public abstract class AbstractStateMachine extends StateMachineObjectSuppo }); }; - java.util.function.Function, ? extends Mono>> handleStage1 = in -> { + Function, ? extends Mono>> handleStage1 = in -> { return Mono.just(in) .map(mapFromTargetSub) .filter(s -> states.contains(s)) @@ -1207,7 +1207,7 @@ public abstract class AbstractStateMachine extends StateMachineObjectSuppo .then(Mono.just(in)); }; - java.util.function.Function, ? extends Mono>> handleStage2 = in -> { + Function, ? extends Mono>> handleStage2 = in -> { return Mono.just(in) .filter(s -> currentState == null && !states.contains(s) && StateMachineUtils.isSubstate(findDeepParent(s), state)) .map(mapFromTargetSub) @@ -1217,7 +1217,7 @@ public abstract class AbstractStateMachine extends StateMachineObjectSuppo .then(Mono.just(in)); }; - java.util.function.Function, ? extends Mono>> handleStage3 = in -> { + Function, ? extends Mono>> handleStage3 = in -> { return Mono.just(in) .map(mapFromTargetSub) .filter(s -> currentState != null && !states.contains(s) && findDeepParent(state) != null) @@ -1226,7 +1226,7 @@ public abstract class AbstractStateMachine extends StateMachineObjectSuppo .then(Mono.just(in)); }; - java.util.function.Function, ? extends Mono>> handleStage4 = in -> { + Function, ? extends Mono>> handleStage4 = in -> { return Mono.just(in) .filter(s -> history != null && transition.getKind() != TransitionKind.INITIAL) .map(mapFromTargetSub) @@ -1246,7 +1246,7 @@ public abstract class AbstractStateMachine extends StateMachineObjectSuppo .then(Mono.just(in)); }; - java.util.function.Function, ? extends Mono>> handleStage5 = in -> { + Function, ? extends Mono>> handleStage5 = in -> { return Mono.just(in).flatMap(handleStop); }; diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/support/Function.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/support/Function.java deleted file mode 100644 index 69c53e8a..00000000 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/support/Function.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.statemachine.support; - -/** - * Mimics Java 8's Function interface to allow deferring a computation. - * - * @author Janne Valkealahti - * - * @param the type of the input to the function - * @param the type of the result of the function - */ -public interface Function { - - /** - * Applies this function to the given argument. - * - * @param t the function argument - * @return the function result - */ - R apply(T t); -} diff --git a/spring-statemachine-core/src/main/java/org/springframework/statemachine/support/StateMachineUtils.java b/spring-statemachine-core/src/main/java/org/springframework/statemachine/support/StateMachineUtils.java index 337e48e8..d0b935ce 100644 --- a/spring-statemachine-core/src/main/java/org/springframework/statemachine/support/StateMachineUtils.java +++ b/spring-statemachine-core/src/main/java/org/springframework/statemachine/support/StateMachineUtils.java @@ -18,6 +18,7 @@ package org.springframework.statemachine.support; import java.util.ArrayList; import java.util.Collection; import java.util.Optional; +import java.util.function.Function; import org.springframework.statemachine.StateContext; import org.springframework.statemachine.StateMachineMessageHeaders; @@ -202,7 +203,7 @@ public abstract class StateMachineUtils { * * @return mono for completion */ - public static java.util.function.Function> resumeErrorToContext() { + public static Function> resumeErrorToContext() { return t -> Mono.subscriberContext() .doOnNext(ctx -> { Optional holder = ctx.getOrEmpty(StateMachineSystemConstants.REACTOR_CONTEXT_ERRORS);