Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.serverlessworkflow.fluent.func;

import io.cloudevents.CloudEventData;
import io.serverlessworkflow.api.reflection.func.SerializableFunction;
import io.serverlessworkflow.api.types.func.ContextFunction;
import io.serverlessworkflow.api.types.func.EventDataFunction;
import io.serverlessworkflow.api.types.func.FilterFunction;
Expand All @@ -31,7 +30,7 @@ protected FuncEmitEventPropertiesBuilder self() {
return this;
}

public <T> FuncEmitEventPropertiesBuilder data(SerializableFunction<T, CloudEventData> function) {
public <T> FuncEmitEventPropertiesBuilder data(Function<T, CloudEventData> function) {
this.eventProperties.setData(new EventDataFunction().withFunction(function));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package io.serverlessworkflow.fluent.func.dsl;

import io.serverlessworkflow.api.reflection.func.ReflectionUtils;
import io.serverlessworkflow.api.reflection.func.SerializableFunction;
import io.serverlessworkflow.api.reflection.func.SerializablePredicate;
import io.serverlessworkflow.api.types.FlowDirectiveEnum;
import io.serverlessworkflow.fluent.func.FuncCallTaskBuilder;
import io.serverlessworkflow.fluent.func.FuncSwitchTaskBuilder;
Expand All @@ -32,9 +29,10 @@ default <T, V> Consumer<FuncCallTaskBuilder> fn(Function<T, V> function, Class<T
return f -> f.function(function, argClass);
}

default <T, V> Consumer<FuncCallTaskBuilder> fn(SerializableFunction<T, V> function) {
Class<T> clazz = ReflectionUtils.inferInputType(function);
return f -> f.function(function, clazz);
@SuppressWarnings("unchecked")
default <T, V> Consumer<FuncCallTaskBuilder> fn(Function<T, V> function, T... typeToken) {
Class<T> clazz = (Class<T>) typeToken.getClass().getComponentType();
return fn(function, clazz);
}

default Consumer<FuncSwitchTaskBuilder> cases(SwitchCaseConfigurer... cases) {
Expand All @@ -49,8 +47,9 @@ default <T> SwitchCaseSpec<T> caseOf(Predicate<T> when, Class<T> whenClass) {
return new SwitchCaseSpec<T>().when(when, whenClass);
}

default <T> SwitchCaseSpec<T> caseOf(SerializablePredicate<T> when) {
return new SwitchCaseSpec<T>().when(when, ReflectionUtils.inferInputType(when));
@SuppressWarnings("unchecked")
default <T> SwitchCaseSpec<T> caseOf(Predicate<T> when, T... typeToken) {
return caseOf(when, (Class<T>) typeToken.getClass().getComponentType());
}

default SwitchCaseConfigurer caseDefault(String task) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public final class FuncCallStep<T, R> extends Step<FuncCallStep<T, R>, FuncCallT
private final Class<T> argClass;
private final Class<R> returnClass;

@SuppressWarnings("unchecked")
private static <R> Class<R> defaultReturnClass(Class<R> c) {
return c != null ? c : (Class<R>) Object.class;
}

/** Function<T,R> variant (unnamed). */
FuncCallStep(Function<T, R> fn, Class<T> argClass, Class<R> returnClass) {
this(null, fn, argClass, returnClass);
Expand All @@ -43,7 +48,7 @@ public final class FuncCallStep<T, R> extends Step<FuncCallStep<T, R>, FuncCallT
this.ctxFn = null;
this.filterFn = null;
this.argClass = argClass;
this.returnClass = returnClass;
this.returnClass = defaultReturnClass(returnClass);
}

/** ContextFunction<T,R> variant (unnamed). */
Expand All @@ -58,7 +63,7 @@ public final class FuncCallStep<T, R> extends Step<FuncCallStep<T, R>, FuncCallT
this.ctxFn = ctxFn;
this.filterFn = null;
this.argClass = argClass;
this.returnClass = returnClass;
this.returnClass = defaultReturnClass(returnClass);
}

/** FilterFunction<T,R> variant (unnamed). */
Expand All @@ -74,7 +79,7 @@ public final class FuncCallStep<T, R> extends Step<FuncCallStep<T, R>, FuncCallT
this.ctxFn = null;
this.filterFn = filterFn;
this.argClass = argClass;
this.returnClass = returnClass;
this.returnClass = defaultReturnClass(returnClass);
}

@Override
Expand Down
Loading