AbstractFunctionCompiler cleanup
- removed Function/Supplier/ConsumerFactories by modifying SOURCE_CODE_TEMPLATE - removed Example main from src/main/java/org.springframework.cloud.function.compiler
This commit is contained in:
committed by
markfisher
parent
2fdfda9416
commit
11b8654e09
@@ -32,6 +32,7 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* @author Andy Clement
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public abstract class AbstractFunctionCompiler<F> {
|
||||
|
||||
@@ -54,12 +55,12 @@ public abstract class AbstractFunctionCompiler<F> {
|
||||
+ "import java.util.*;\n" // Helpful to include this
|
||||
+ "import java.util.function.*;\n"
|
||||
+ "import reactor.core.publisher.Flux;\n"
|
||||
+ "public class %s implements %sFactory {\n"
|
||||
+ " public %s<%s> getResult() {\n"
|
||||
+ "public class %s implements CompilationResultFactory<%s> {\n"
|
||||
+ " public %s<%s> getResult() {\n"
|
||||
+ " %s\n"
|
||||
+ " }\n"
|
||||
+ "}\n";
|
||||
// @formatter:on
|
||||
// @formatter:on
|
||||
|
||||
static enum ResultType {
|
||||
Consumer, Function, Supplier
|
||||
@@ -177,7 +178,7 @@ public abstract class AbstractFunctionCompiler<F> {
|
||||
String shortClassName = className.substring(className.lastIndexOf('.') + 1);
|
||||
String s = String.format(SOURCE_CODE_TEMPLATE, shortClassName, resultType,
|
||||
resultType, StringUtils.arrayToCommaDelimitedString(types), methodBody);
|
||||
System.out.println(s);
|
||||
logger.info("\n" + s);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 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
|
||||
*
|
||||
* http://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.cloud.function.compiler;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public interface ConsumerFactory<T> extends CompilationResultFactory<Consumer<T>> {
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 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
|
||||
*
|
||||
* http://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.cloud.function.compiler;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class Example {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SupplierCompiler<Flux<String>> supplierCompiler = new SupplierCompiler<>();
|
||||
CompiledFunctionFactory<Supplier<Flux<String>>> supplierFactory = supplierCompiler.compile("s", "return ()->Flux.just(\"foo\");");
|
||||
Flux<String> input = supplierFactory.getResult().get();
|
||||
|
||||
FunctionCompiler<Flux<String>, Flux<String>> functionCompiler = new FunctionCompiler<>();
|
||||
CompiledFunctionFactory<Function<Flux<String>,Flux<String>>> functionFactory = functionCompiler.compile("f", "f->f.map(s->s.toString().toUpperCase())");
|
||||
Flux<String> output = functionFactory.getResult().apply(input);
|
||||
|
||||
ConsumerCompiler<String> consumerCompiler = new ConsumerCompiler<>();
|
||||
CompiledFunctionFactory<Consumer<String>> consumerFactory = consumerCompiler.compile("c", "System.out::println");
|
||||
output.subscribe(consumerFactory.getResult());
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 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
|
||||
*
|
||||
* http://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.cloud.function.compiler;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public interface FunctionFactory<T, R> extends CompilationResultFactory<Function<T, R>> {
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 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
|
||||
*
|
||||
* http://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.cloud.function.compiler;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public interface SupplierFactory<T> extends CompilationResultFactory<Supplier<T>> {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user