Apply Some Java 8 Code Changes
* Make most functional interfaces as `@FunctionalInterface` * Convert some abstract classes to `@FunctionalInterface` with `default` methods * Apply Lambda style implementation in some places * Remove `Function` in favor of similar in Java 8 * Remove redundant code from `DefaultAmqpHeaderMapper` since we are already on Spring AMQP-2.0 * Add several ctors to the `ExpressionEvaluatingMessageListProcessor` * Populate explicit `Boolean.class` `expectedType` from the `ExpressionEvaluatingReleaseStrategy`
This commit is contained in:
committed by
Gary Russell
parent
89e0d134f5
commit
370be4853d
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -25,6 +25,7 @@ import org.springframework.messaging.Message;
|
||||
* @author Marius Bogoevici
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface CorrelationStrategy {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -22,29 +22,41 @@ import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ParseException;
|
||||
import org.springframework.integration.util.AbstractExpressionEvaluator;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A base class for aggregators that evaluates a SpEL expression with the message list as the root object within the
|
||||
* evaluation context.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ExpressionEvaluatingMessageListProcessor extends AbstractExpressionEvaluator implements MessageListProcessor {
|
||||
public class ExpressionEvaluatingMessageListProcessor extends AbstractExpressionEvaluator
|
||||
implements MessageListProcessor {
|
||||
|
||||
private final Expression expression;
|
||||
|
||||
private volatile Class<?> expectedType = null;
|
||||
|
||||
/**
|
||||
* Set the result type expected from evaluation of the expression.
|
||||
*
|
||||
* @param expectedType The expected type.
|
||||
* Construct {@link ExpressionEvaluatingMessageListProcessor} for the provided
|
||||
* SpEL expression and expected result type.
|
||||
* @param expression a SpEL expression to evaluate in {@link #process(Collection)}.
|
||||
* @param expectedType an expected result type.
|
||||
* @since 5.0
|
||||
*/
|
||||
public void setExpectedType(Class<?> expectedType) {
|
||||
public ExpressionEvaluatingMessageListProcessor(String expression, Class<?> expectedType) {
|
||||
this(expression);
|
||||
this.expectedType = expectedType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct {@link ExpressionEvaluatingMessageListProcessor} for the provided
|
||||
* SpEL expression and expected result type.
|
||||
* @param expression a SpEL expression to evaluate in {@link #process(Collection)}.
|
||||
* @since 5.0
|
||||
*/
|
||||
public ExpressionEvaluatingMessageListProcessor(String expression) {
|
||||
try {
|
||||
this.expression = EXPRESSION_PARSER.parseExpression(expression);
|
||||
@@ -54,6 +66,36 @@ public class ExpressionEvaluatingMessageListProcessor extends AbstractExpression
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct {@link ExpressionEvaluatingMessageListProcessor} for the provided
|
||||
* expression and expected result type.
|
||||
* @param expression an expression to evaluate in {@link #process(Collection)}.
|
||||
* @param expectedType an expected result type.
|
||||
* @since 5.0
|
||||
*/
|
||||
public ExpressionEvaluatingMessageListProcessor(Expression expression, Class<?> expectedType) {
|
||||
this(expression);
|
||||
this.expectedType = expectedType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct {@link ExpressionEvaluatingMessageListProcessor} for the provided expression.
|
||||
* @param expression an expression to evaluate in {@link #process(Collection)}.
|
||||
* @since 5.0
|
||||
*/
|
||||
public ExpressionEvaluatingMessageListProcessor(Expression expression) {
|
||||
Assert.notNull(expression, "'expression' must not be null.");
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the result type expected from evaluation of the expression.
|
||||
* @param expectedType The expected type.
|
||||
*/
|
||||
public void setExpectedType(Class<?> expectedType) {
|
||||
this.expectedType = expectedType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the Message by evaluating the expression with that Message as the root object. The expression
|
||||
* evaluation result Object will be returned.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -27,7 +27,7 @@ public class ExpressionEvaluatingReleaseStrategy extends ExpressionEvaluatingMes
|
||||
ReleaseStrategy {
|
||||
|
||||
public ExpressionEvaluatingReleaseStrategy(String expression) {
|
||||
super(expression);
|
||||
super(expression, Boolean.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ public class ExpressionEvaluatingReleaseStrategy extends ExpressionEvaluatingMes
|
||||
* be boolean).
|
||||
*/
|
||||
public boolean canRelease(MessageGroup messages) {
|
||||
return ((Boolean) process(messages.getMessages())).booleanValue();
|
||||
return (Boolean) process(messages.getMessages());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.integration.store.MessageGroup;
|
||||
* @author Iwein Fuld
|
||||
* @see org.springframework.integration.aggregator.AbstractCorrelatingMessageHandler
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MessageGroupProcessor {
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.messaging.Message;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MessageListProcessor {
|
||||
|
||||
Object process(Collection<? extends Message<?>> messages);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -27,6 +27,7 @@ import org.springframework.integration.store.MessageGroup;
|
||||
* @author Mark Fisher
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ReleaseStrategy {
|
||||
|
||||
boolean canRelease(MessageGroup group);
|
||||
|
||||
@@ -116,7 +116,7 @@ public abstract class ThreadStatePropagationChannelInterceptor<S>
|
||||
|
||||
@Override
|
||||
public Message<?> decorateMessage(Message<?> message) {
|
||||
return new MessageWithThreadState<S>(message, this.state);
|
||||
return new MessageWithThreadState<>(message, this.state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
* @author Artem Bilan
|
||||
* @since 4.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IntegrationConfigurationInitializer {
|
||||
|
||||
void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -24,6 +24,7 @@ package org.springframework.integration.core;
|
||||
* @author Artem Bilan
|
||||
* @since 4.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface GenericSelector<S> {
|
||||
|
||||
boolean accept(S source);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -23,6 +23,7 @@ import org.springframework.messaging.Message;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MessageSelector extends GenericSelector<Message<?>> {
|
||||
|
||||
boolean accept(Message<?> message);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -23,6 +23,7 @@ import org.springframework.messaging.Message;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MessageSource<T> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.messaging.MessageHandler;
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 1.0.3
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface LoadBalancingStrategy {
|
||||
|
||||
Iterator<MessageHandler> getHandlerIterator(Message<?> message, Collection<MessageHandler> handlers);
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.messaging.support.MessageHandlingRunnable;
|
||||
* @see UnicastingDispatcher
|
||||
* @see BroadcastingDispatcher
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MessageHandlingTaskDecorator {
|
||||
|
||||
Runnable decorate(MessageHandlingRunnable task);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -26,6 +26,7 @@ import org.springframework.expression.Expression;
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ExpressionSource {
|
||||
|
||||
Expression getExpression(String key, Locale locale);
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.messaging.Message;
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface RequestReplyExchanger {
|
||||
|
||||
Message<?> exchange(Message<?> request);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -39,6 +39,7 @@ import org.springframework.messaging.Message;
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MessageProcessor<T> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-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.
|
||||
@@ -26,6 +26,7 @@ import org.springframework.messaging.Message;
|
||||
* @since 4.2
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MessageTriggerAction {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -23,6 +23,7 @@ import org.springframework.messaging.Message;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface InboundMessageMapper<T> {
|
||||
|
||||
Message<?> toMessage(T object) throws Exception;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -23,6 +23,7 @@ import org.springframework.messaging.Message;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface OutboundMessageMapper<T> {
|
||||
|
||||
T fromMessage(Message<?> message) throws Exception;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-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.
|
||||
@@ -27,6 +27,7 @@ import org.springframework.messaging.Message;
|
||||
* @since 4.1
|
||||
* @see org.springframework.integration.handler.AbstractMessageProducingHandler
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface RoutingSlipRouteStrategy {
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
|
||||
import org.springframework.integration.util.Function;
|
||||
import org.springframework.integration.util.FunctionIterator;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
@@ -89,7 +88,7 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess
|
||||
|
||||
Map<String, Object> messageHeaders = message.getHeaders();
|
||||
if (willAddHeaders(message)) {
|
||||
messageHeaders = new HashMap<String, Object>(messageHeaders);
|
||||
messageHeaders = new HashMap<>(messageHeaders);
|
||||
addHeaders(message, messageHeaders);
|
||||
}
|
||||
final Map<String, Object> headers = messageHeaders;
|
||||
@@ -97,15 +96,8 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess
|
||||
final AtomicInteger sequenceNumber = new AtomicInteger(1);
|
||||
|
||||
return new FunctionIterator<Object, AbstractIntegrationMessageBuilder<?>>(iterator,
|
||||
new Function<Object, AbstractIntegrationMessageBuilder<?>>() {
|
||||
|
||||
@Override
|
||||
public AbstractIntegrationMessageBuilder<?> apply(Object object) {
|
||||
return createBuilder(object, headers, correlationId, sequenceNumber.getAndIncrement(),
|
||||
sequenceSize);
|
||||
}
|
||||
|
||||
});
|
||||
object ->
|
||||
createBuilder(object, headers, correlationId, sequenceNumber.getAndIncrement(), sequenceSize));
|
||||
}
|
||||
|
||||
private AbstractIntegrationMessageBuilder<?> createBuilder(Object item, Map<String, Object> headers,
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.messaging.Message;
|
||||
* @author Artem Bilan
|
||||
* @since 4.2.9
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MessageDecorator {
|
||||
|
||||
Message<?> decorateMessage(Message<?> message);
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.concurrent.locks.Lock;
|
||||
* @author Gary Russell
|
||||
* @since 2.1.1
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface LockRegistry {
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,6 +23,7 @@ package org.springframework.integration.support.management;
|
||||
* @since 4.2
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ConfigurableMetricsAware<M extends ConfigurableMetrics> {
|
||||
|
||||
void configureMetrics(M metrics);
|
||||
|
||||
@@ -25,6 +25,7 @@ package org.springframework.integration.transformer;
|
||||
* @author Artem Bilan
|
||||
* @since 4.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface GenericTransformer<S, T> {
|
||||
|
||||
T transform(S source);
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.messaging.Message;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Transformer extends GenericTransformer<Message<?>, Message<?>> {
|
||||
|
||||
Message<?> transform(Message<?> message);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -25,6 +25,7 @@ import java.util.Collection;
|
||||
* @author Mark Fisher
|
||||
* @since 2.1
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface CollectionFilter<T> {
|
||||
|
||||
Collection<T> filter(Collection<T> unfilteredElements);
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-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.integration.util;
|
||||
|
||||
/**
|
||||
* Implementations of this class perform work on the given parameter
|
||||
* and return a result of an optionally different type.
|
||||
*
|
||||
* <p>This is a copy of Java 8 {@code Function} interface.
|
||||
*
|
||||
* @param <T> The type of the input to the apply operation
|
||||
* @param <R> The type of the result of the apply operation
|
||||
*
|
||||
* @author Jon Brisbin
|
||||
* @author Stephane Maldini
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface Function<T, R> {
|
||||
|
||||
/**
|
||||
* Execute the logic of the action, accepting the given parameter.
|
||||
* @param t The parameter to pass to the action.
|
||||
* @return result
|
||||
*/
|
||||
R apply(T t);
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* An {@link Iterator} implementation to convert each item from the target
|
||||
|
||||
Reference in New Issue
Block a user