Remove Function interface

- Switch from org.springframework.statemachine.support.Function
  to java.util.function.Function.
- Fixes #867
This commit is contained in:
Janne Valkealahti
2020-09-13 14:29:02 +01:00
parent d9e2ed5425
commit e78811eaa9
4 changed files with 15 additions and 49 deletions

View File

@@ -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;

View File

@@ -1074,7 +1074,7 @@ public abstract class AbstractStateMachine<S, E> extends StateMachineObjectSuppo
private Mono<Void> setCurrentStateInternal3(State<S, E> state, Message<E> message, Transition<S, E> transition, boolean exit,
StateMachine<S, E> stateMachine, Collection<State<S, E>> sources, Collection<State<S, E>> targets) {
java.util.function.Function<State<S, E>, State<S, E>> mapFromTargetSub = in -> {
Function<State<S, E>, State<S, E>> 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<S, E> extends StateMachineObjectSuppo
return in;
};
java.util.function.Function<State<S, E>, ? extends Mono<State<S, E>>> handleExit = in -> {
Function<State<S, E>, ? extends Mono<State<S, E>>> handleExit = in -> {
if (exit) {
return exitCurrentState(in, message, transition, stateMachine, sources, targets)
.then(Mono.just(in))
@@ -1093,14 +1093,14 @@ public abstract class AbstractStateMachine<S, E> extends StateMachineObjectSuppo
return Mono.just(in);
};
java.util.function.Function<State<S, E>, ? extends Mono<State<S, E>>> handleStart = in -> {
Function<State<S, E>, ? extends Mono<State<S, E>>> handleStart = in -> {
if (!isRunning() && !isComplete()) {
return startReactively().then(Mono.just(in));
}
return Mono.just(in);
};
java.util.function.Function<State<S, E>, ? extends Mono<State<S, E>>> handleEntry1 = in -> {
Function<State<S, E>, ? extends Mono<State<S, E>>> handleEntry1 = in -> {
State<S, E> notifyFrom = currentState;
currentState = in;
return entryToState(in, message, transition, stateMachine)
@@ -1112,7 +1112,7 @@ public abstract class AbstractStateMachine<S, E> extends StateMachineObjectSuppo
});
};
java.util.function.Function<State<S, E>, ? extends Mono<State<S, E>>> handleEntry2 = in -> {
Function<State<S, E>, ? extends Mono<State<S, E>>> handleEntry2 = in -> {
State<S, E> notifyFrom = currentState;
State<S, E> findDeep = findDeepParent(in);
currentState = findDeep;
@@ -1125,14 +1125,14 @@ public abstract class AbstractStateMachine<S, E> extends StateMachineObjectSuppo
});
};
java.util.function.Function<State<S, E>, ? extends Mono<State<S, E>>> handleStop = s -> {
Function<State<S, E>, ? extends Mono<State<S, E>>> handleStop = s -> {
if (stateMachine != this && isComplete()) {
return stopReactively().then(Mono.just(s));
}
return Mono.just(s);
};
java.util.function.Function<State<S, E>, ? extends Mono<State<S, E>>> handleSubmachineOrRegions = in -> {
Function<State<S, E>, ? extends Mono<State<S, E>>> handleSubmachineOrRegions = in -> {
return Mono.just(in)
.flatMap(s -> {
if (currentState == findDeepParent(s)) {
@@ -1197,7 +1197,7 @@ public abstract class AbstractStateMachine<S, E> extends StateMachineObjectSuppo
});
};
java.util.function.Function<State<S, E>, ? extends Mono<State<S, E>>> handleStage1 = in -> {
Function<State<S, E>, ? extends Mono<State<S, E>>> handleStage1 = in -> {
return Mono.just(in)
.map(mapFromTargetSub)
.filter(s -> states.contains(s))
@@ -1207,7 +1207,7 @@ public abstract class AbstractStateMachine<S, E> extends StateMachineObjectSuppo
.then(Mono.just(in));
};
java.util.function.Function<State<S, E>, ? extends Mono<State<S, E>>> handleStage2 = in -> {
Function<State<S, E>, ? extends Mono<State<S, E>>> 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<S, E> extends StateMachineObjectSuppo
.then(Mono.just(in));
};
java.util.function.Function<State<S, E>, ? extends Mono<State<S, E>>> handleStage3 = in -> {
Function<State<S, E>, ? extends Mono<State<S, E>>> 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<S, E> extends StateMachineObjectSuppo
.then(Mono.just(in));
};
java.util.function.Function<State<S, E>, ? extends Mono<State<S, E>>> handleStage4 = in -> {
Function<State<S, E>, ? extends Mono<State<S, E>>> handleStage4 = in -> {
return Mono.just(in)
.filter(s -> history != null && transition.getKind() != TransitionKind.INITIAL)
.map(mapFromTargetSub)
@@ -1246,7 +1246,7 @@ public abstract class AbstractStateMachine<S, E> extends StateMachineObjectSuppo
.then(Mono.just(in));
};
java.util.function.Function<State<S, E>, ? extends Mono<State<S, E>>> handleStage5 = in -> {
Function<State<S, E>, ? extends Mono<State<S, E>>> handleStage5 = in -> {
return Mono.just(in).flatMap(handleStop);
};

View File

@@ -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 <T> the type of the input to the function
* @param <R> the type of the result of the function
*/
public interface Function<T, R> {
/**
* Applies this function to the given argument.
*
* @param t the function argument
* @return the function result
*/
R apply(T t);
}

View File

@@ -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<? super Throwable, Mono<Void>> resumeErrorToContext() {
public static Function<? super Throwable, Mono<Void>> resumeErrorToContext() {
return t -> Mono.subscriberContext()
.doOnNext(ctx -> {
Optional<ExecutorExceptionHolder> holder = ctx.getOrEmpty(StateMachineSystemConstants.REACTOR_CONTEXT_ERRORS);