diff --git a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/FunctionEntry.java b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/FunctionEntry.java deleted file mode 100644 index 8cfbe44b2..000000000 --- a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/FunctionEntry.java +++ /dev/null @@ -1,44 +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 - * - * 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.context; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.core.annotation.AliasFor; - -/** - * A {@link Qualifier} annotation that specifies how to locate a function in the - * {@link FunctionCatalog} (instead of using the bean name). - * - * @author Dave Syer - */ -@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, - ElementType.ANNOTATION_TYPE }) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -@Documented -@Qualifier -public @interface FunctionEntry { - @AliasFor(annotation=Qualifier.class) - String value() default ""; -} diff --git a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/config/ContextFunctionCatalogAutoConfiguration.java b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/config/ContextFunctionCatalogAutoConfiguration.java index 501bf3b78..2a89fd9db 100644 --- a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/config/ContextFunctionCatalogAutoConfiguration.java +++ b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/config/ContextFunctionCatalogAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 the original author or authors. + * Copyright 2016-2018 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. @@ -36,6 +36,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; +import java.util.stream.Stream; import javax.annotation.PreDestroy; @@ -382,40 +383,18 @@ public class ContextFunctionCatalogAutoConfiguration { registrations.add(registration); targets.put(registration.getTarget(), key); } - // Add consumers that were not already registered - for (String key : consumers.keySet()) { - if (!targets.containsKey(consumers.get(key))) { - FunctionRegistration target = new FunctionRegistration( - consumers.get(key)).names(getAliases(key)); - targets.put(target.getTarget(), key); - registrations.add(target); - } - } - // Add suppliers that were not already registered - for (String key : suppliers.keySet()) { - if (!targets.containsKey(suppliers.get(key))) { - FunctionRegistration target = new FunctionRegistration( - suppliers.get(key)).names(getAliases(key)); - targets.put(target.getTarget(), key); - registrations.add(target); - } - } - // Add functions that were not already registered - for (String key : functions.keySet()) { - if (!targets.containsKey(functions.get(key))) { - FunctionRegistration target = new FunctionRegistration( - functions.get(key)).names(getAliases(key)); - targets.put(target.getTarget(), key); - registrations.add(target); - } - } + + Stream.concat(consumers.entrySet().stream(), Stream.concat(suppliers.entrySet().stream(), functions.entrySet().stream())) + .forEach(entry -> { + if (!targets.containsKey(entry.getValue())) { + FunctionRegistration target = new FunctionRegistration( + entry.getValue()).names(getAliases(entry.getKey())); + targets.put(target.getTarget(), entry.getKey()); + registrations.add(target); + } + }); // Wrap the functions so they handle reactive inputs and outputs - for (FunctionRegistration registration : registrations) { - @SuppressWarnings("unchecked") - FunctionRegistration target = (FunctionRegistration) registration; - String key = targets.get(target.getTarget()); - wrap(target, key); - } + registrations.forEach(registration -> wrap(registration, targets.get(registration.getTarget()))); return registrations; }