This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new dd8bfa86e7d (chores) convert core/camel-support to use pattern
matching for instanceof
dd8bfa86e7d is described below
commit dd8bfa86e7d638b8852f8364070574d46d1a98c5
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Wed Aug 21 13:19:42 2024 +0200
(chores) convert core/camel-support to use pattern matching for instanceof
---
.../camel/converter/stream/CachedOutputStream.java | 4 +-
.../org/apache/camel/support/AbstractExchange.java | 17 ++-
.../camel/support/AbstractVariableRepository.java | 3 +-
.../support/AsyncProcessorConverterHelper.java | 8 +-
.../apache/camel/support/CamelContextHelper.java | 4 +-
.../apache/camel/support/ChildServiceSupport.java | 4 +-
.../org/apache/camel/support/DefaultComponent.java | 17 ++-
.../org/apache/camel/support/DefaultConsumer.java | 4 +-
.../org/apache/camel/support/DefaultEndpoint.java | 16 +--
.../org/apache/camel/support/DefaultRegistry.java | 8 +-
.../org/apache/camel/support/DeferProducer.java | 4 +-
.../org/apache/camel/support/EndpointHelper.java | 11 +-
.../camel/support/EventDrivenPollingConsumer.java | 9 +-
.../org/apache/camel/support/ExchangeHelper.java | 48 ++++----
.../support/ExpressionToPredicateAdapter.java | 20 +--
.../apache/camel/support/GroupTokenIterator.java | 10 +-
.../support/HeaderFilterStrategyComponent.java | 4 +-
.../org/apache/camel/support/LanguageHelper.java | 43 +++----
.../org/apache/camel/support/LanguageSupport.java | 7 +-
.../camel/support/LifecycleStrategySupport.java | 27 ++---
.../org/apache/camel/support/LoggerHelper.java | 20 +--
.../org/apache/camel/support/MessageHelper.java | 24 ++--
.../org/apache/camel/support/ObjectHelper.java | 134 ++++++++++-----------
.../apache/camel/support/OrderedComparator.java | 8 +-
.../camel/support/PredicateAssertHelper.java | 3 +-
.../support/PredicateToExpressionAdapter.java | 4 +-
.../camel/support/PropertyBindingSupport.java | 67 +++++------
.../camel/support/PropertyConfigurerHelper.java | 4 +-
.../org/apache/camel/support/ResolverHelper.java | 16 +--
.../camel/support/RouteVariableRepository.java | 3 +-
.../camel/support/ScheduledPollConsumer.java | 4 +-
.../camel/support/ScheduledPollEndpoint.java | 10 +-
.../org/apache/camel/support/SupplierRegistry.java | 20 +--
.../camel/support/builder/ExpressionBuilder.java | 4 +-
.../camel/support/builder/OutputStreamBuilder.java | 4 +-
.../apache/camel/support/builder/ValueBuilder.java | 12 +-
.../camel/support/cache/DefaultProducerCache.java | 4 +-
.../support/component/AbstractApiComponent.java | 3 +-
.../support/component/AbstractApiEndpoint.java | 4 +-
.../support/component/AbstractApiProducer.java | 3 +-
.../camel/support/component/ApiConsumerHelper.java | 4 +-
.../camel/support/component/ApiMethodHelper.java | 7 +-
.../component/ApiMethodPropertiesHelper.java | 14 +--
.../component/EndpointUriFactorySupport.java | 3 +-
.../component/PropertyConfigurerSupport.java | 3 +-
.../support/jndi/CamelInitialContextFactory.java | 4 +-
.../org/apache/camel/support/jndi/JndiContext.java | 15 ++-
.../DefaultManagementMBeanAssembler.java | 8 +-
.../camel/support/processor/RestBindingAdvice.java | 8 +-
.../camel/support/resume/ResumeStrategyHelper.java | 4 +-
50 files changed, 319 insertions(+), 370 deletions(-)
diff --git
a/core/camel-support/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
b/core/camel-support/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
index 50ac9150f9a..d53f0ea3a9b 100644
---
a/core/camel-support/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
+++
b/core/camel-support/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
@@ -142,8 +142,8 @@ public class CachedOutputStream extends OutputStream {
flush();
if (inMemory) {
- if (currentStream instanceof CachedByteArrayOutputStream) {
- return ((CachedByteArrayOutputStream)
currentStream).newInputStreamCache();
+ if (currentStream instanceof CachedByteArrayOutputStream
cachedByteArrayOutputStream) {
+ return cachedByteArrayOutputStream.newInputStreamCache();
} else {
throw new IllegalStateException(
"CurrentStream should be an instance of
CachedByteArrayOutputStream but is: "
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java
b/core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java
index e059b0e32a0..98d1cabd2cb 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java
@@ -508,13 +508,19 @@ abstract class AbstractExchange implements Exchange {
public Message getOut() {
// lazy create
if (out == null) {
- out = (in instanceof MessageSupport)
- ? ((MessageSupport) in).newInstance() : new
DefaultMessage(getContext());
+ out = newOutMessage();
configureMessage(out);
}
return out;
}
+ private Message newOutMessage() {
+ if (in instanceof MessageSupport messageSupport) {
+ return messageSupport.newInstance();
+ }
+ return new DefaultMessage(getContext());
+ }
+
@SuppressWarnings("deprecated")
@Override
public <T> T getOut(Class<T> type) {
@@ -580,8 +586,8 @@ abstract class AbstractExchange implements Exchange {
public void setException(Throwable t) {
if (t == null) {
this.exception = null;
- } else if (t instanceof Exception) {
- this.exception = (Exception) t;
+ } else if (t instanceof Exception exception) {
+ this.exception = exception;
} else {
// wrap throwable into an exception
this.exception =
CamelExecutionException.wrapCamelExecutionException(this, t);
@@ -685,8 +691,7 @@ abstract class AbstractExchange implements Exchange {
* Configures the message after it has been set on the exchange
*/
protected void configureMessage(Message message) {
- if (message instanceof MessageSupport) {
- MessageSupport messageSupport = (MessageSupport) message;
+ if (message instanceof MessageSupport messageSupport) {
messageSupport.setExchange(this);
messageSupport.setCamelContext(getContext());
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/AbstractVariableRepository.java
b/core/camel-support/src/main/java/org/apache/camel/support/AbstractVariableRepository.java
index ba6655b0541..ad5152652c0 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/AbstractVariableRepository.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/AbstractVariableRepository.java
@@ -120,8 +120,7 @@ public abstract class AbstractVariableRepository extends
ServiceSupport
// check if body is already cached
if (body == null) {
return null;
- } else if (body instanceof StreamCache) {
- StreamCache sc = (StreamCache) body;
+ } else if (body instanceof StreamCache sc) {
// reset so the cache is ready to be used before processing
sc.reset();
return sc;
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/AsyncProcessorConverterHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/AsyncProcessorConverterHelper.java
index cbfedb08919..455f582f3f6 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/AsyncProcessorConverterHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/AsyncProcessorConverterHelper.java
@@ -189,15 +189,15 @@ public final class AsyncProcessorConverterHelper {
}
public static AsyncProducer convert(Producer value) {
- if (value instanceof AsyncProducer) {
- return (AsyncProducer) value;
+ if (value instanceof AsyncProducer asyncProducer) {
+ return asyncProducer;
}
return new ProducerToAsyncProducerBridge(value);
}
public static AsyncProcessor convert(Processor value) {
- if (value instanceof AsyncProcessor) {
- return (AsyncProcessor) value;
+ if (value instanceof AsyncProcessor asyncProcessor) {
+ return asyncProcessor;
}
return new ProcessorToAsyncProcessorBridge(value);
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/CamelContextHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/CamelContextHelper.java
index 7b81d586be7..462f6c52be9 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/CamelContextHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/CamelContextHelper.java
@@ -562,8 +562,8 @@ public final class CamelContextHelper {
while (parent != null && parent.getParent() != null) {
parent = parent.getParent();
}
- if (parent instanceof NamedRoute) {
- return (NamedRoute) parent;
+ if (parent instanceof NamedRoute namedRoute) {
+ return namedRoute;
}
return null;
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/ChildServiceSupport.java
b/core/camel-support/src/main/java/org/apache/camel/support/ChildServiceSupport.java
index a0293f89cf8..063e1b0277b 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/ChildServiceSupport.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/ChildServiceSupport.java
@@ -132,13 +132,13 @@ public abstract class ChildServiceSupport extends
ServiceSupport {
}
protected void addChildService(Object childService) {
- if (childService instanceof Service) {
+ if (childService instanceof Service service) {
lock.lock();
try {
if (childServices == null) {
childServices = new ArrayList<>();
}
- childServices.add((Service) childService);
+ childServices.add(service);
} finally {
lock.unlock();
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
index 577b92bfe3d..5e70d60749e 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
@@ -176,8 +176,7 @@ public abstract class DefaultComponent extends
ServiceSupport implements Compone
endpoint.setCamelContext(getCamelContext());
// and setup those global options afterwards
- if (endpoint instanceof DefaultEndpoint) {
- DefaultEndpoint de = (DefaultEndpoint) endpoint;
+ if (endpoint instanceof DefaultEndpoint de) {
de.setBridgeErrorHandler(bridge);
de.setLazyStartProducer(lazy);
de.setAutowiredEnabled(autowire);
@@ -193,8 +192,8 @@ public abstract class DefaultComponent extends
ServiceSupport implements Compone
}
// allow custom configuration after properties has been configured
- if (endpoint instanceof AfterPropertiesConfigured) {
- ((AfterPropertiesConfigured)
endpoint).afterPropertiesConfigured(getCamelContext());
+ if (endpoint instanceof AfterPropertiesConfigured
afterPropertiesConfigured) {
+
afterPropertiesConfigured.afterPropertiesConfigured(getCamelContext());
}
afterConfiguration(uri, path, endpoint, parameters);
@@ -449,8 +448,8 @@ public abstract class DefaultComponent extends
ServiceSupport implements Compone
configurer = getComponentPropertyConfigurer();
} else if (bean instanceof Endpoint) {
configurer = getEndpointPropertyConfigurer();
- } else if (bean instanceof PropertyConfigurerAware) {
- configurer = ((PropertyConfigurerAware)
bean).getPropertyConfigurer(bean);
+ } else if (bean instanceof PropertyConfigurerAware
propertyConfigurerAware) {
+ configurer = propertyConfigurerAware.getPropertyConfigurer(bean);
} else {
configurer = null;
}
@@ -543,8 +542,7 @@ public abstract class DefaultComponent extends
ServiceSupport implements Compone
Map<String, Object> parameters, String key, Class<T> type, T
defaultValue) {
// the parameter may be the the type already (such as from
endpoint-dsl)
Object value = parameters.remove(key);
- if (value instanceof String) {
- String str = (String) value;
+ if (value instanceof String str) {
if (EndpointHelper.isReferenceParameter(str)) {
return
EndpointHelper.resolveReferenceParameter(getCamelContext(), str, type);
}
@@ -600,8 +598,7 @@ public abstract class DefaultComponent extends
ServiceSupport implements Compone
public <T> T resolveAndRemoveReferenceParameter(Map<String, Object>
parameters, String key, Class<T> type, T defaultValue) {
// the parameter may be the the type already (such as from
endpoint-dsl)
Object value = parameters.remove(key);
- if (value instanceof String) {
- String str = (String) value;
+ if (value instanceof String str) {
if (EndpointHelper.isReferenceParameter(str)) {
return
EndpointHelper.resolveReferenceParameter(getCamelContext(), str, type);
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultConsumer.java
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultConsumer.java
index 7371e5be57d..5c8fbcd9fc1 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultConsumer.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultConsumer.java
@@ -147,9 +147,9 @@ public class DefaultConsumer extends ServiceSupport
@Override
public void releaseExchange(Exchange exchange, boolean autoRelease) {
if (exchange != null) {
- if (!autoRelease && exchange instanceof PooledExchange) {
+ if (!autoRelease && exchange instanceof PooledExchange
pooledExchange) {
// if not auto release we must manually force done
- ((PooledExchange) exchange).done();
+ pooledExchange.done();
}
exchangeFactory.release(exchange);
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
index 67a4ac5d016..2ff0c296aa0 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
@@ -127,8 +127,7 @@ public abstract class DefaultEndpoint extends
ServiceSupport implements Endpoint
@Override
public boolean equals(Object object) {
- if (object instanceof DefaultEndpoint) {
- DefaultEndpoint that = (DefaultEndpoint) object;
+ if (object instanceof DefaultEndpoint that) {
// must also match the same CamelContext in case we compare
endpoints from different contexts
String thisContextName = this.getCamelContext() != null ?
this.getCamelContext().getName() : null;
String thatContextName = that.getCamelContext() != null ?
that.getCamelContext().getName() : null;
@@ -414,8 +413,8 @@ public abstract class DefaultEndpoint extends
ServiceSupport implements Endpoint
configurer = getComponent().getComponentPropertyConfigurer();
} else if (bean instanceof Endpoint) {
configurer = getComponent().getEndpointPropertyConfigurer();
- } else if (bean instanceof PropertyConfigurerAware) {
- configurer = ((PropertyConfigurerAware)
bean).getPropertyConfigurer(bean);
+ } else if (bean instanceof PropertyConfigurerAware
propertyConfigurerAware) {
+ configurer = propertyConfigurerAware.getPropertyConfigurer(bean);
}
// use configurer and ignore case as end users may type an option name
with mixed case
PropertyBindingSupport.build().withConfigurer(configurer).withIgnoreCase(true)
@@ -469,8 +468,7 @@ public abstract class DefaultEndpoint extends
ServiceSupport implements Endpoint
CamelContextAware.trySetCamelContext(consumer, camelContext);
if (bridgeErrorHandler) {
- if (consumer instanceof DefaultConsumer) {
- DefaultConsumer defaultConsumer = (DefaultConsumer) consumer;
+ if (consumer instanceof DefaultConsumer defaultConsumer) {
defaultConsumer.setExceptionHandler(new
BridgeExceptionHandlerToErrorHandler(defaultConsumer));
} else {
throw new IllegalArgumentException(
@@ -480,8 +478,7 @@ public abstract class DefaultEndpoint extends
ServiceSupport implements Endpoint
}
}
if (exceptionHandler != null) {
- if (consumer instanceof DefaultConsumer) {
- DefaultConsumer defaultConsumer = (DefaultConsumer) consumer;
+ if (consumer instanceof DefaultConsumer defaultConsumer) {
defaultConsumer.setExceptionHandler(exceptionHandler);
}
}
@@ -497,8 +494,7 @@ public abstract class DefaultEndpoint extends
ServiceSupport implements Endpoint
if (autowiredEnabled && getComponent() != null &&
getComponent().isAutowiredEnabled()) {
PropertyConfigurer configurer =
getComponent().getEndpointPropertyConfigurer();
- if (configurer instanceof PropertyConfigurerGetter) {
- PropertyConfigurerGetter getter = (PropertyConfigurerGetter)
configurer;
+ if (configurer instanceof PropertyConfigurerGetter getter) {
String[] names = getter.getAutowiredNames();
if (names != null) {
for (String name : names) {
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultRegistry.java
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultRegistry.java
index 0c1971c9b19..89181a36964 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultRegistry.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultRegistry.java
@@ -384,11 +384,11 @@ public class DefaultRegistry extends ServiceSupport
implements Registry, LocalBe
@Override
protected void doStop() throws Exception {
super.doStop();
- if (supplierRegistry instanceof Closeable) {
- IOHelper.close((Closeable) supplierRegistry);
+ if (supplierRegistry instanceof Closeable closeable) {
+ IOHelper.close(closeable);
}
- if (fallbackRegistry instanceof Closeable) {
- IOHelper.close((Closeable) fallbackRegistry);
+ if (fallbackRegistry instanceof Closeable closeable) {
+ IOHelper.close(closeable);
}
ServiceHelper.stopAndShutdownServices(supplierRegistry,
fallbackRegistry);
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/DeferProducer.java
b/core/camel-support/src/main/java/org/apache/camel/support/DeferProducer.java
index b94b26a312f..afdcbfa6b81 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/DeferProducer.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/DeferProducer.java
@@ -56,8 +56,8 @@ public class DeferProducer extends ServiceSupport implements
Producer, AsyncProc
return true;
}
- if (delegate instanceof AsyncProcessor) {
- return ((AsyncProcessor) delegate).process(exchange, callback);
+ if (delegate instanceof AsyncProcessor asyncProcessor) {
+ return asyncProcessor.process(exchange, callback);
}
// fallback to sync mode
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
index 436c3db3ffb..f728f31068d 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
@@ -136,8 +136,7 @@ public final class EndpointHelper {
continue;
}
Object value = entry.getValue();
- if (value instanceof String) {
- String s = value.toString();
+ if (value instanceof String s) {
if (s.startsWith(prefix)) {
continue;
}
@@ -443,9 +442,9 @@ public final class EndpointHelper {
List<String> elements = Arrays.asList(value.split(","));
if (elements.size() == 1) {
Object bean = resolveReferenceParameter(context,
elements.get(0).trim(), Object.class);
- if (bean instanceof List) {
+ if (bean instanceof List list) {
// The bean is a list
- return (List) bean;
+ return list;
} else {
// The bean is a list element
List<T> singleElementList = new ArrayList<>();
@@ -525,8 +524,8 @@ public final class EndpointHelper {
// it may be a delegate endpoint, which we need to match as well
Endpoint delegate = null;
- if (endpoint instanceof DelegateEndpoint) {
- delegate = ((DelegateEndpoint) endpoint).getEndpoint();
+ if (endpoint instanceof DelegateEndpoint delegateEndpoint) {
+ delegate = delegateEndpoint.getEndpoint();
}
Map<String, Endpoint> map =
endpoint.getCamelContext().getRegistry().findByTypeWithName(Endpoint.class);
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/EventDrivenPollingConsumer.java
b/core/camel-support/src/main/java/org/apache/camel/support/EventDrivenPollingConsumer.java
index 6d785810014..e91acd07df6 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/EventDrivenPollingConsumer.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/EventDrivenPollingConsumer.java
@@ -239,8 +239,7 @@ public class EventDrivenPollingConsumer extends
PollingConsumerSupport implement
}
protected long beforePoll(long timeout) {
- if (consumer instanceof PollingConsumerPollingStrategy) {
- PollingConsumerPollingStrategy strategy =
(PollingConsumerPollingStrategy) consumer;
+ if (consumer instanceof PollingConsumerPollingStrategy strategy) {
try {
timeout = strategy.beforePoll(timeout);
} catch (Exception e) {
@@ -251,8 +250,7 @@ public class EventDrivenPollingConsumer extends
PollingConsumerSupport implement
}
protected void afterPoll() {
- if (consumer instanceof PollingConsumerPollingStrategy) {
- PollingConsumerPollingStrategy strategy =
(PollingConsumerPollingStrategy) consumer;
+ if (consumer instanceof PollingConsumerPollingStrategy strategy) {
try {
strategy.afterPoll();
} catch (Exception e) {
@@ -285,8 +283,7 @@ public class EventDrivenPollingConsumer extends
PollingConsumerSupport implement
@Override
protected void doStart() throws Exception {
// if the consumer has a polling strategy then invoke that
- if (consumer instanceof PollingConsumerPollingStrategy) {
- PollingConsumerPollingStrategy strategy =
(PollingConsumerPollingStrategy) consumer;
+ if (consumer instanceof PollingConsumerPollingStrategy strategy) {
strategy.onInit();
} else {
ServiceHelper.startService(consumer);
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
index fa0287db087..f1faee71d0a 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
@@ -125,10 +125,9 @@ public final class ExchangeHelper {
throw new NoSuchEndpointException("null");
}
Endpoint endpoint;
- if (value instanceof Endpoint) {
- endpoint = (Endpoint) value;
- } else if (value instanceof NormalizedEndpointUri) {
- NormalizedEndpointUri nu = (NormalizedEndpointUri) value;
+ if (value instanceof Endpoint ep) {
+ endpoint = ep;
+ } else if (value instanceof NormalizedEndpointUri nu) {
endpoint = CamelContextHelper.getMandatoryEndpoint(context, nu);
} else {
String uri = value.toString().trim();
@@ -164,10 +163,9 @@ public final class ExchangeHelper {
throw new NoSuchEndpointException("null");
}
Endpoint endpoint;
- if (value instanceof Endpoint) {
- endpoint = (Endpoint) value;
- } else if (value instanceof NormalizedEndpointUri) {
- NormalizedEndpointUri nu = (NormalizedEndpointUri) value;
+ if (value instanceof Endpoint ep) {
+ endpoint = ep;
+ } else if (value instanceof NormalizedEndpointUri nu) {
endpoint =
CamelContextHelper.getMandatoryPrototypeEndpoint(context, nu);
} else {
String uri = value.toString().trim();
@@ -785,8 +783,7 @@ public final class ExchangeHelper {
if (type.isAssignableFrom(result.getClass())) {
return type.cast(result);
}
- if (result instanceof Exchange) {
- Exchange exchange = (Exchange) result;
+ if (result instanceof Exchange exchange) {
Object answer = ExchangeHelper.extractResultBody(exchange,
exchange.getPattern());
return context.getTypeConverter().convertTo(type, exchange,
answer);
}
@@ -867,8 +864,8 @@ public final class ExchangeHelper {
}
// need to de-reference old from the exchange so it can be GC
- if (old instanceof MessageSupport) {
- ((MessageSupport) old).setExchange(null);
+ if (old instanceof MessageSupport messageSupport) {
+ messageSupport.setExchange(null);
}
}
@@ -993,8 +990,7 @@ public final class ExchangeHelper {
* @return the scanner, is newer <tt>null</tt>
*/
public static Scanner getScanner(Exchange exchange, Object value, String
delimiter) {
- if (value instanceof WrappedFile) {
- WrappedFile<?> gf = (WrappedFile<?>) value;
+ if (value instanceof WrappedFile gf) {
Object body = gf.getBody();
if (body != null) {
// we have loaded the file content into the body so use that
@@ -1006,22 +1002,22 @@ public final class ExchangeHelper {
}
Scanner scanner;
- if (value instanceof Readable) {
- scanner = new Scanner((Readable) value, delimiter);
- } else if (value instanceof String) {
- scanner = new Scanner((String) value, delimiter);
+ if (value instanceof Readable readable) {
+ scanner = new Scanner(readable, delimiter);
+ } else if (value instanceof String str) {
+ scanner = new Scanner(str, delimiter);
} else {
String charset =
exchange.getProperty(ExchangePropertyKey.CHARSET_NAME, String.class);
- if (value instanceof File) {
+ if (value instanceof File file) {
try {
- scanner = new Scanner((File) value, charset, delimiter);
+ scanner = new Scanner(file, charset, delimiter);
} catch (IOException e) {
throw new RuntimeCamelException(e);
}
- } else if (value instanceof InputStream) {
- scanner = new Scanner((InputStream) value, charset, delimiter);
- } else if (value instanceof ReadableByteChannel) {
- scanner = new Scanner((ReadableByteChannel) value, charset,
delimiter);
+ } else if (value instanceof InputStream inputStream) {
+ scanner = new Scanner(inputStream, charset, delimiter);
+ } else if (value instanceof ReadableByteChannel
readableByteChannel) {
+ scanner = new Scanner(readableByteChannel, charset, delimiter);
} else {
// value is not a suitable type, try to convert value to a
string
String text =
exchange.getContext().getTypeConverter().convertTo(String.class, exchange,
value);
@@ -1273,8 +1269,8 @@ public final class ExchangeHelper {
*/
public static <T> T getBodyAndResetStreamCache(Exchange exchange, Class<T>
type) {
Object body = exchange.getMessage().getBody();
- if (body instanceof StreamCache) {
- ((StreamCache) body).reset();
+ if (body instanceof StreamCache sc) {
+ sc.reset();
}
return exchange.getMessage().getBody(type);
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/ExpressionToPredicateAdapter.java
b/core/camel-support/src/main/java/org/apache/camel/support/ExpressionToPredicateAdapter.java
index b81b612a9fe..b513ed924e2 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/ExpressionToPredicateAdapter.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/ExpressionToPredicateAdapter.java
@@ -37,8 +37,8 @@ public final class ExpressionToPredicateAdapter implements
Predicate, CamelConte
@Override
public boolean matches(Exchange exchange) {
- if (expression instanceof Predicate) {
- return ((Predicate) expression).matches(exchange);
+ if (expression instanceof Predicate predicate) {
+ return predicate.matches(exchange);
} else {
Object value = expression.evaluate(exchange, Object.class);
return ObjectHelper.evaluateValuePredicate(value);
@@ -54,8 +54,8 @@ public final class ExpressionToPredicateAdapter implements
Predicate, CamelConte
* Converts the given expression into an {@link Predicate}
*/
public static Predicate toPredicate(final Expression expression) {
- if (expression instanceof Predicate) {
- return (Predicate) expression;
+ if (expression instanceof Predicate predicate) {
+ return predicate;
}
return new ExpressionToPredicateAdapter(expression);
}
@@ -72,8 +72,8 @@ public final class ExpressionToPredicateAdapter implements
Predicate, CamelConte
@Override
public CamelContext getCamelContext() {
- if (expression instanceof CamelContextAware) {
- return ((CamelContextAware) expression).getCamelContext();
+ if (expression instanceof CamelContextAware camelContext) {
+ return camelContext.getCamelContext();
} else {
return null;
}
@@ -81,10 +81,10 @@ public final class ExpressionToPredicateAdapter implements
Predicate, CamelConte
@Override
public PropertyConfigurer getPropertyConfigurer(Object instance) {
- if (expression instanceof PropertyConfigurer) {
- return (PropertyConfigurer) expression;
- } else if (expression instanceof PropertyConfigurerAware) {
- return ((PropertyConfigurerAware)
expression).getPropertyConfigurer(expression);
+ if (expression instanceof PropertyConfigurer propertyConfigurer) {
+ return propertyConfigurer;
+ } else if (expression instanceof PropertyConfigurerAware
propertyConfigurer) {
+ return propertyConfigurer.getPropertyConfigurer(expression);
} else {
return null;
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/GroupTokenIterator.java
b/core/camel-support/src/main/java/org/apache/camel/support/GroupTokenIterator.java
index b7fbd56e422..386469f3c3a 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/GroupTokenIterator.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/GroupTokenIterator.java
@@ -67,8 +67,8 @@ public final class GroupTokenIterator implements
Iterator<Object>, Closeable {
this.it = it;
// if the iterator is a scanner then it may have a dynamic delimiter
// so we need to use the actual evaluated delimiter as token
- if (LanguageSupport.hasSimpleFunction(token) && it instanceof Scanner)
{
- this.token = ((Scanner) it).getDelim();
+ if (LanguageSupport.hasSimpleFunction(token) && it instanceof Scanner
scanner) {
+ this.token = scanner.getDelim();
} else {
this.token = token;
}
@@ -142,11 +142,9 @@ public final class GroupTokenIterator implements
Iterator<Object>, Closeable {
if (data != null && count > 0 && token != null) {
bos.write(token.getBytes());
}
- if (data instanceof InputStream) {
- InputStream is = (InputStream) data;
+ if (data instanceof InputStream is) {
IOHelper.copy(is, bos);
- } else if (data instanceof byte[]) {
- byte[] bytes = (byte[]) data;
+ } else if (data instanceof byte[] bytes) {
bos.write(bytes);
} else if (data != null) {
// convert to input stream
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/HeaderFilterStrategyComponent.java
b/core/camel-support/src/main/java/org/apache/camel/support/HeaderFilterStrategyComponent.java
index 7efc1df792e..4e10fe283e8 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/HeaderFilterStrategyComponent.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/HeaderFilterStrategyComponent.java
@@ -56,8 +56,8 @@ public abstract class HeaderFilterStrategyComponent extends
DefaultComponent imp
* {@link HeaderFilterStrategyAware} type.
*/
public void setEndpointHeaderFilterStrategy(Endpoint endpoint) {
- if (headerFilterStrategy != null && endpoint instanceof
HeaderFilterStrategyAware) {
- ((HeaderFilterStrategyAware)
endpoint).setHeaderFilterStrategy(headerFilterStrategy);
+ if (headerFilterStrategy != null && endpoint instanceof
HeaderFilterStrategyAware aware) {
+ aware.setHeaderFilterStrategy(headerFilterStrategy);
}
}
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/LanguageHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/LanguageHelper.java
index e2e37bf38f8..03fd5350720 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/LanguageHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/LanguageHelper.java
@@ -214,14 +214,11 @@ public final class LanguageHelper {
return date;
}
- public static Date dateFromExchangeProperty(
- Exchange exchange, String command, BiFunction<Exchange, Object,
Date> orElseFunction) {
- final String key = command.substring(command.lastIndexOf('.') + 1);
- final Object obj = exchange.getProperty(key);
- if (obj instanceof Date) {
- return (Date) obj;
- } else if (obj instanceof Long) {
- return new Date((Long) obj);
+ private static Date toDate(Exchange exchange, BiFunction<Exchange, Object,
Date> orElseFunction, Object obj) {
+ if (obj instanceof Date date) {
+ return date;
+ } else if (obj instanceof Long date) {
+ return new Date(date);
} else {
if (orElseFunction != null) {
return orElseFunction.apply(exchange, obj);
@@ -230,34 +227,24 @@ public final class LanguageHelper {
return null;
}
+ public static Date dateFromExchangeProperty(
+ Exchange exchange, String command, BiFunction<Exchange, Object,
Date> orElseFunction) {
+ final String key = command.substring(command.lastIndexOf('.') + 1);
+ final Object obj = exchange.getProperty(key);
+
+ return toDate(exchange, orElseFunction, obj);
+ }
+
public static Date dateFromHeader(Exchange exchange, String command,
BiFunction<Exchange, Object, Date> orElseFunction) {
final String key = command.substring(command.lastIndexOf('.') + 1);
final Object obj = exchange.getMessage().getHeader(key);
- if (obj instanceof Date) {
- return (Date) obj;
- } else if (obj instanceof Long) {
- return new Date((Long) obj);
- } else {
- if (orElseFunction != null) {
- return orElseFunction.apply(exchange, obj);
- }
- }
- return null;
+ return toDate(exchange, orElseFunction, obj);
}
public static Date dateFromVariable(Exchange exchange, String command,
BiFunction<Exchange, Object, Date> orElseFunction) {
final String key = command.substring(command.lastIndexOf('.') + 1);
final Object obj = exchange.getVariable(key);
- if (obj instanceof Date) {
- return (Date) obj;
- } else if (obj instanceof Long) {
- return new Date((Long) obj);
- } else {
- if (orElseFunction != null) {
- return orElseFunction.apply(exchange, obj);
- }
- }
- return null;
+ return toDate(exchange, orElseFunction, obj);
}
/**
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/LanguageSupport.java
b/core/camel-support/src/main/java/org/apache/camel/support/LanguageSupport.java
index cc55a0f3117..8872fa13969 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/LanguageSupport.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/LanguageSupport.java
@@ -124,8 +124,8 @@ public abstract class LanguageSupport implements Language,
IsSingleton, CamelCon
value = defaultValue;
}
- if (camelContext != null && value instanceof String) {
- value =
getCamelContext().resolvePropertyPlaceholders(value.toString());
+ if (camelContext != null && value instanceof String str) {
+ value = getCamelContext().resolvePropertyPlaceholders(str);
}
// if the type is not string based and the value is a bean reference,
then we need to lookup
@@ -169,8 +169,7 @@ public abstract class LanguageSupport implements Language,
IsSingleton, CamelCon
}
// special for boolean values with string values as we only want to
accept "true" or "false"
- if ((type == Boolean.class || type == boolean.class) && value
instanceof String) {
- String text = (String) value;
+ if ((type == Boolean.class || type == boolean.class) && value
instanceof String text) {
if (!text.equalsIgnoreCase("true") &&
!text.equalsIgnoreCase("false")) {
throw new IllegalArgumentException(
"Cannot convert the String value: " + value + " to
type: " + type
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/LifecycleStrategySupport.java
b/core/camel-support/src/main/java/org/apache/camel/support/LifecycleStrategySupport.java
index 61a6e384974..7218c2ba55c 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/LifecycleStrategySupport.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/LifecycleStrategySupport.java
@@ -55,43 +55,43 @@ public abstract class LifecycleStrategySupport implements
LifecycleStrategy {
return new LifecycleStrategySupport() {
@Override
public void onContextInitializing(CamelContext context) throws
VetoCamelContextStartException {
- if (handler instanceof OnCamelContextInitializing) {
- ((OnCamelContextInitializing)
handler).onContextInitializing(context);
+ if (handler instanceof OnCamelContextInitializing
onCamelContextInitializing) {
+ onCamelContextInitializing.onContextInitializing(context);
}
}
@Override
public void onContextInitialized(CamelContext context) throws
VetoCamelContextStartException {
- if (handler instanceof OnCamelContextInitialized) {
- ((OnCamelContextInitialized)
handler).onContextInitialized(context);
+ if (handler instanceof OnCamelContextInitialized
onCamelContextInitialized) {
+ onCamelContextInitialized.onContextInitialized(context);
}
}
@Override
public void onContextStarting(CamelContext context) throws
VetoCamelContextStartException {
- if (handler instanceof OnCamelContextStarting) {
- ((OnCamelContextStarting)
handler).onContextStarting(context);
+ if (handler instanceof OnCamelContextStarting
onCamelContextStarting) {
+ onCamelContextStarting.onContextStarting(context);
}
}
@Override
public void onContextStarted(CamelContext context) {
- if (handler instanceof OnCamelContextStarted) {
- ((OnCamelContextStarted)
handler).onContextStarted(context);
+ if (handler instanceof OnCamelContextStarted
onCamelContextStarted) {
+ onCamelContextStarted.onContextStarted(context);
}
}
@Override
public void onContextStopping(CamelContext context) {
- if (handler instanceof OnCamelContextStopping) {
- ((OnCamelContextStopping)
handler).onContextStopping(context);
+ if (handler instanceof OnCamelContextStopping
onCamelContextStopping) {
+ onCamelContextStopping.onContextStopping(context);
}
}
@Override
public void onContextStopped(CamelContext context) {
- if (handler instanceof OnCamelContextStopped) {
- ((OnCamelContextStopped)
handler).onContextStopped(context);
+ if (handler instanceof OnCamelContextStopped
onCamelContextStopped) {
+ onCamelContextStopped.onContextStopped(context);
}
}
};
@@ -247,8 +247,7 @@ public abstract class LifecycleStrategySupport implements
LifecycleStrategy {
protected static void doAutoWire(String name, String kind, Object target,
CamelContext camelContext) {
PropertyConfigurer pc =
PluginHelper.getConfigurerResolver(camelContext)
.resolvePropertyConfigurer(name + "-" + kind, camelContext);
- if (pc instanceof PropertyConfigurerGetter) {
- PropertyConfigurerGetter getter = (PropertyConfigurerGetter) pc;
+ if (pc instanceof PropertyConfigurerGetter getter) {
String[] names = getter.getAutowiredNames();
if (names != null) {
for (String option : names) {
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/LoggerHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/LoggerHelper.java
index b0495908de6..35c419c3e54 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/LoggerHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/LoggerHelper.java
@@ -39,12 +39,14 @@ public final class LoggerHelper {
public static String getLineNumberLoggerName(Object node) {
String name = null;
if (node instanceof LineNumberAware) {
- if (node instanceof NamedRoute) {
+ if (node instanceof NamedRoute namedRoute) {
// we want the input from a route as it has the source
location / line number
- node = ((NamedRoute) node).getInput();
+ node = namedRoute.getInput();
}
- String loc = ((LineNumberAware) node).getLocation();
- int line = ((LineNumberAware) node).getLineNumber();
+
+ final LineNumberAware lineNumberAware = (LineNumberAware) node;
+ String loc = lineNumberAware.getLocation();
+ int line = lineNumberAware.getLineNumber();
if (loc != null) {
// is it a class or file?
name = loc;
@@ -72,12 +74,14 @@ public final class LoggerHelper {
public static String getSourceLocation(Object node) {
String name = null;
if (node instanceof LineNumberAware) {
- if (node instanceof NamedRoute) {
+ if (node instanceof NamedRoute namedRoute) {
// we want the input from a route as it has the source
location / line number
- node = ((NamedRoute) node).getInput();
+ node = namedRoute.getInput();
}
- String loc = ((LineNumberAware) node).getLocation();
- int line = ((LineNumberAware) node).getLineNumber();
+
+ final LineNumberAware lineNumberAware = (LineNumberAware) node;
+ String loc = lineNumberAware.getLocation();
+ int line = lineNumberAware.getLineNumber();
if (loc != null) {
// is it a class or file?
name = loc;
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/MessageHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/MessageHelper.java
index e0254811abe..73c46203ab8 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/MessageHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/MessageHelper.java
@@ -75,8 +75,8 @@ public final class MessageHelper {
// optimize if the body is a String type already
Object body = message.getBody();
- if (body instanceof String) {
- return (String) body;
+ if (body instanceof String string) {
+ return string;
}
// we need to favor using stream cache so the body can be re-read later
@@ -133,8 +133,8 @@ public final class MessageHelper {
} catch (Exception e) {
// ignore
}
- if (body instanceof StreamCache) {
- ((StreamCache) body).reset();
+ if (body instanceof StreamCache streamCache) {
+ streamCache.reset();
}
}
@@ -373,10 +373,10 @@ public final class MessageHelper {
// is the body a stream cache or input stream
StreamCache cache = null;
InputStream is = null;
- if (obj instanceof StreamCache) {
- cache = (StreamCache) obj;
- } else if (obj instanceof InputStream) {
- is = (InputStream) obj;
+ if (obj instanceof StreamCache streamCache) {
+ cache = streamCache;
+ } else if (obj instanceof InputStream inputStream) {
+ is = inputStream;
}
// grab the message body as a string
@@ -628,8 +628,8 @@ public final class MessageHelper {
int size = Array.getLength(body);
sb.append(" size=\"").append(size).append("\"");
}
- if (body instanceof StreamCache) {
- long pos = ((StreamCache) body).position();
+ if (body instanceof StreamCache streamCache) {
+ long pos = streamCache.position();
if (pos != -1) {
sb.append(" position=\"").append(pos).append("\"");
}
@@ -1079,8 +1079,8 @@ public final class MessageHelper {
int size = Array.getLength(body);
jb.put("size", size);
}
- if (body instanceof StreamCache) {
- long pos = ((StreamCache) body).position();
+ if (body instanceof StreamCache streamCache) {
+ long pos = streamCache.position();
if (pos != -1) {
jb.put("position", pos);
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java
index 42f71e5c3db..3bc8b75b28c 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java
@@ -96,17 +96,17 @@ public final class ObjectHelper {
// optimize for common combinations of comparing numbers
if (leftValue instanceof String) {
return typeCoerceString(converter, leftValue, rightValue,
ignoreCase);
- } else if (rightValue instanceof String &&
- (leftValue instanceof Integer || leftValue instanceof Long) &&
isNumber((String) rightValue)) {
- return typeCoerceIntLong(leftValue, (String) rightValue);
+ } else if (rightValue instanceof String str &&
+ (leftValue instanceof Integer || leftValue instanceof Long) &&
isNumber(str)) {
+ return typeCoerceIntLong(leftValue, str);
} else if (leftValue instanceof Integer && rightValue instanceof
Integer) {
return integerPairComparison(leftValue, rightValue);
} else if (leftValue instanceof Long && rightValue instanceof Long) {
return longPairComparison(leftValue, rightValue);
} else if (leftValue instanceof Double && rightValue instanceof
Double) {
return doublePairComparison(leftValue, rightValue);
- } else if (rightValue instanceof String && leftValue instanceof
Boolean) {
- return booleanStringComparison((Boolean) leftValue, (String)
rightValue);
+ } else if (rightValue instanceof String string && leftValue instanceof
Boolean booleanValue) {
+ return booleanStringComparison(booleanValue, string);
}
// try without type coerce
@@ -114,13 +114,13 @@ public final class ObjectHelper {
}
private static boolean typeCoerceString(TypeConverter converter, Object
leftValue, Object rightValue, boolean ignoreCase) {
- if (rightValue instanceof String) {
- return typeCoerceStringPair((String) leftValue, (String)
rightValue, ignoreCase);
+ if (rightValue instanceof String string) {
+ return typeCoerceStringPair((String) leftValue, string,
ignoreCase);
} else if ((rightValue instanceof Integer || rightValue instanceof
Long) &&
isNumber((String) leftValue)) {
return typeCoerceILString((String) leftValue, rightValue);
- } else if (rightValue instanceof Double && isFloatingNumber((String)
leftValue)) {
- return stringDoubleComparison((String) leftValue, (Double)
rightValue);
+ } else if (rightValue instanceof Double doubleValue &&
isFloatingNumber((String) leftValue)) {
+ return stringDoubleComparison((String) leftValue, doubleValue);
} else if (rightValue instanceof Boolean) {
return stringBooleanComparison(leftValue, rightValue);
}
@@ -151,8 +151,8 @@ public final class ObjectHelper {
// convert left to right
StreamCache sc = null;
try {
- if (leftValue instanceof StreamCache) {
- sc = (StreamCache) leftValue;
+ if (leftValue instanceof StreamCache streamCache) {
+ sc = streamCache;
}
Object value = converter.tryConvertTo(rightValue.getClass(),
leftValue);
final boolean isEqualLeftToRight =
org.apache.camel.util.ObjectHelper.equal(value, rightValue, ignoreCase);
@@ -161,8 +161,8 @@ public final class ObjectHelper {
}
// convert right to left
- if (rightValue instanceof StreamCache) {
- sc = (StreamCache) rightValue;
+ if (rightValue instanceof StreamCache streamCache) {
+ sc = streamCache;
}
value = converter.tryConvertTo(leftValue.getClass(), rightValue);
return org.apache.camel.util.ObjectHelper.equal(leftValue, value,
ignoreCase);
@@ -261,52 +261,23 @@ public final class ObjectHelper {
public static int typeCoerceCompare(TypeConverter converter, Object
leftValue, Object rightValue) {
// optimize for common combinations of comparing numbers
- if (leftValue instanceof String && rightValue instanceof String) {
- String leftNum = (String) leftValue;
- String rightNum = (String) rightValue;
- // prioritize non-floating numbers first
- Long num1 = isNumber(leftNum) ? Long.parseLong(leftNum) : null;
- Long num2 = isNumber(rightNum) ? Long.parseLong(rightNum) : null;
- Double dec1 = num1 == null && isFloatingNumber(leftNum) ?
Double.parseDouble(leftNum) : null;
- Double dec2 = num2 == null && isFloatingNumber(rightNum) ?
Double.parseDouble(rightNum) : null;
- if (num1 != null && num2 != null) {
- return num1.compareTo(num2);
- } else if (dec1 != null && dec2 != null) {
- return dec1.compareTo(dec2);
- }
- // okay mixed but we need to convert to floating
- if (num1 != null && dec2 != null) {
- dec1 = Double.parseDouble(leftNum);
- return dec1.compareTo(dec2);
- } else if (num2 != null && dec1 != null) {
- dec2 = Double.parseDouble(rightNum);
- return dec1.compareTo(dec2);
- }
- // fallback to string comparison
+ if (leftValue instanceof String leftNum && rightValue instanceof
String rightNum) {
+ return typeCoerceCompareStringString(leftNum, rightNum);
+ } else if (leftValue instanceof Integer leftNum && rightValue
instanceof Integer rightNum) {
return leftNum.compareTo(rightNum);
- } else if (leftValue instanceof Integer && rightValue instanceof
Integer) {
- Integer leftNum = (Integer) leftValue;
- Integer rightNum = (Integer) rightValue;
+ } else if (leftValue instanceof Long leftNum && rightValue instanceof
Long rightNum) {
return leftNum.compareTo(rightNum);
- } else if (leftValue instanceof Long && rightValue instanceof Long) {
- Long leftNum = (Long) leftValue;
- Long rightNum = (Long) rightValue;
- return leftNum.compareTo(rightNum);
- } else if (leftValue instanceof Double && rightValue instanceof
Double) {
- Double leftNum = (Double) leftValue;
- Double rightNum = (Double) rightValue;
+ } else if (leftValue instanceof Double leftNum && rightValue
instanceof Double rightNum) {
return leftNum.compareTo(rightNum);
- } else if (leftValue instanceof Float && rightValue instanceof Float) {
- Float leftNum = (Float) leftValue;
- Float rightNum = (Float) rightValue;
+ } else if (leftValue instanceof Float leftNum && rightValue instanceof
Float rightNum) {
return leftNum.compareTo(rightNum);
} else if ((rightValue instanceof Integer || rightValue instanceof
Long) &&
- leftValue instanceof String && isNumber((String) leftValue)) {
+ leftValue instanceof String leftStr && isNumber(leftStr)) {
if (rightValue instanceof Integer rightNum) {
- Integer leftNum = Integer.valueOf((String) leftValue);
+ Integer leftNum = Integer.valueOf(leftStr);
return leftNum.compareTo(rightNum);
} else {
- Long leftNum = Long.valueOf((String) leftValue);
+ Long leftNum = Long.valueOf(leftStr);
Long rightNum = (Long) rightValue;
return leftNum.compareTo(rightNum);
}
@@ -361,18 +332,18 @@ public final class ObjectHelper {
}
// prefer to coerce to the right hand side at first
- if (rightValue instanceof Comparable) {
+ if (rightValue instanceof Comparable rightComparable) {
Object value = converter.tryConvertTo(rightValue.getClass(),
leftValue);
if (value != null) {
- return ((Comparable) rightValue).compareTo(value) * -1;
+ return rightComparable.compareTo(value) * -1;
}
}
// then fallback to the left hand side
- if (leftValue instanceof Comparable) {
+ if (leftValue instanceof Comparable leftComparable) {
Object value = converter.tryConvertTo(leftValue.getClass(),
rightValue);
if (value != null) {
- return ((Comparable) leftValue).compareTo(value);
+ return leftComparable.compareTo(value);
}
}
@@ -380,6 +351,29 @@ public final class ObjectHelper {
return compare(leftValue, rightValue);
}
+ private static int typeCoerceCompareStringString(String leftNum, String
rightNum) {
+ // prioritize non-floating numbers first
+ Long num1 = isNumber(leftNum) ? Long.parseLong(leftNum) : null;
+ Long num2 = isNumber(rightNum) ? Long.parseLong(rightNum) : null;
+ Double dec1 = num1 == null && isFloatingNumber(leftNum) ?
Double.parseDouble(leftNum) : null;
+ Double dec2 = num2 == null && isFloatingNumber(rightNum) ?
Double.parseDouble(rightNum) : null;
+ if (num1 != null && num2 != null) {
+ return num1.compareTo(num2);
+ } else if (dec1 != null && dec2 != null) {
+ return dec1.compareTo(dec2);
+ }
+ // okay mixed but we need to convert to floating
+ if (num1 != null && dec2 != null) {
+ dec1 = Double.parseDouble(leftNum);
+ return dec1.compareTo(dec2);
+ } else if (num2 != null && dec1 != null) {
+ dec2 = Double.parseDouble(rightNum);
+ return dec1.compareTo(dec2);
+ }
+ // fallback to string comparison
+ return leftNum.compareTo(rightNum);
+ }
+
/**
* Checks whether the text is an integer number
*/
@@ -571,14 +565,13 @@ public final class ObjectHelper {
if (b == null) {
return 1;
}
- if (a instanceof Ordered && b instanceof Ordered) {
- return ((Ordered) a).getOrder() - ((Ordered) b).getOrder();
+ if (a instanceof Ordered orderedA && b instanceof Ordered orderedB) {
+ return orderedA.getOrder() - orderedB.getOrder();
}
- if (ignoreCase && a instanceof String && b instanceof String) {
- return ((String) a).compareToIgnoreCase((String) b);
+ if (ignoreCase && a instanceof String strA && b instanceof String
strB) {
+ return strA.compareToIgnoreCase(strB);
}
- if (a instanceof Comparable) {
- Comparable comparable = (Comparable) a;
+ if (a instanceof Comparable comparable) {
return comparable.compareTo(b);
}
int answer = a.getClass().getName().compareTo(b.getClass().getName());
@@ -742,8 +735,8 @@ public final class ObjectHelper {
* @return the iterator
*/
public static Iterator<?> createIterator(Object value, String delimiter,
boolean allowEmptyValues) {
- if (value instanceof Stream) {
- return ((Stream) value).iterator();
+ if (value instanceof Stream stream) {
+ return stream.iterator();
}
return createIterable(value, delimiter, allowEmptyValues,
false).iterator();
}
@@ -767,8 +760,8 @@ public final class ObjectHelper {
public static Iterator<?> createIterator(
Object value, String delimiter,
boolean allowEmptyValues, boolean pattern) {
- if (value instanceof Stream) {
- return ((Stream) value).iterator();
+ if (value instanceof Stream stream) {
+ return stream.iterator();
}
return createIterable(value, delimiter, allowEmptyValues,
pattern).iterator();
}
@@ -816,8 +809,8 @@ public final class ObjectHelper {
final boolean allowEmptyValues, final boolean pattern) {
// if its a message than we want to iterate its body
- if (value instanceof Message) {
- value = ((Message) value).getBody();
+ if (value instanceof Message message) {
+ value = message.getBody();
}
if (value == null) {
@@ -1032,11 +1025,10 @@ public final class ObjectHelper {
} else {
return collection.contains(value);
}
- } else if (collectionOrArray instanceof String) {
- String str = (String) collectionOrArray;
+ } else if (collectionOrArray instanceof String str) {
String subStr;
- if (value instanceof String) {
- subStr = (String) value;
+ if (value instanceof String strValue) {
+ subStr = strValue;
} else {
subStr = typeConverter.tryConvertTo(String.class, value);
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/OrderedComparator.java
b/core/camel-support/src/main/java/org/apache/camel/support/OrderedComparator.java
index 03726dc16cd..e95e4c74af8 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/OrderedComparator.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/OrderedComparator.java
@@ -62,11 +62,11 @@ public final class OrderedComparator implements
Comparator<Object> {
public int compare(Object o1, Object o2) {
int num1 = 0;
int num2 = 0;
- if (o1 instanceof Ordered) {
- num1 = ((Ordered) o1).getOrder();
+ if (o1 instanceof Ordered ordered1) {
+ num1 = ordered1.getOrder();
}
- if (o2 instanceof Ordered) {
- num2 = ((Ordered) o2).getOrder();
+ if (o2 instanceof Ordered ordered2) {
+ num2 = ordered2.getOrder();
}
int answer = Integer.compare(num1, num2);
return reverse ? -1 * answer : answer;
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/PredicateAssertHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/PredicateAssertHelper.java
index f3a9284a2f1..db6fbca4265 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/PredicateAssertHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/PredicateAssertHelper.java
@@ -34,9 +34,8 @@ public final class PredicateAssertHelper {
ObjectHelper.notNull(predicate, "predicate");
ObjectHelper.notNull(exchange, "exchange");
- if (predicate instanceof BinaryPredicate) {
+ if (predicate instanceof BinaryPredicate eval) {
// with binary evaluations as we can get more detailed information
- BinaryPredicate eval = (BinaryPredicate) predicate;
String evalText = eval.matchesReturningFailureMessage(exchange);
if (evalText != null) {
throw new AssertionError(text + predicate + " evaluated as: "
+ evalText + " on " + exchange);
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/PredicateToExpressionAdapter.java
b/core/camel-support/src/main/java/org/apache/camel/support/PredicateToExpressionAdapter.java
index 13f8b162fd4..27384c1f9a1 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/PredicateToExpressionAdapter.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/PredicateToExpressionAdapter.java
@@ -45,8 +45,8 @@ public final class PredicateToExpressionAdapter implements
Expression {
* Converts the given predicate into an {@link org.apache.camel.Expression}
*/
public static Expression toExpression(final Predicate predicate) {
- if (predicate instanceof Expression) {
- return (Expression) predicate;
+ if (predicate instanceof Expression expression) {
+ return expression;
}
return new PredicateToExpressionAdapter(predicate);
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 30b9076c4f4..f59025f8a26 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -175,10 +175,10 @@ public final class PropertyBindingSupport {
}
PropertyConfigurer configurer = null;
- if (target instanceof Component) {
+ if (target instanceof Component component) {
// the component needs to be initialized to have the configurer
ready
ServiceHelper.initService(target);
- configurer = ((Component) target).getComponentPropertyConfigurer();
+ configurer = component.getComponentPropertyConfigurer();
}
if (configurer == null) {
@@ -383,13 +383,13 @@ public final class PropertyBindingSupport {
} else {
// okay ognl path is success (either get existing or created
empty object)
// now lets update the target/name/class before next iterator
(next part)
- if (configurer instanceof PropertyConfigurerGetter) {
+ if (configurer instanceof PropertyConfigurerGetter
propertyConfigurerGetter) {
// lets see if we have a specialized configurer
String key = StringHelper.before(part, "[", part);
// if its a map/list/array type then find out what type
the collection uses
// so we can use that to lookup as configurer
- Class<?> collectionType = (Class<?>)
((PropertyConfigurerGetter) configurer)
+ Class<?> collectionType = (Class<?>)
propertyConfigurerGetter
.getCollectionValueType(newTarget, undashKey(key),
ignoreCase);
if (collectionType == null) {
@@ -451,8 +451,8 @@ public final class PropertyBindingSupport {
Object answer = null;
Class<?> parameterType = null;
- if (configurer instanceof PropertyConfigurerGetter) {
- parameterType = ((PropertyConfigurerGetter)
configurer).getOptionType(key, true);
+ if (configurer instanceof PropertyConfigurerGetter
propertyConfigurerGetter) {
+ parameterType = propertyConfigurerGetter.getOptionType(key, true);
}
if (parameterType != null) {
Object obj = getObjectForType(camelContext, parameterType);
@@ -514,9 +514,8 @@ public final class PropertyBindingSupport {
if (placeholder) {
// resolve property placeholders
key = camelContext.resolvePropertyPlaceholders(key);
- if (text instanceof String) {
+ if (text instanceof String s) {
// resolve property placeholders
- String s = text.toString();
text = camelContext.resolvePropertyPlaceholders(s);
if (text == null &&
s.startsWith(PropertiesComponent.PREFIX_TOKEN + "?")) {
// it was an optional value, so we should not try to set
the property but regard it as a "hit"
@@ -530,9 +529,9 @@ public final class PropertyBindingSupport {
Object str = resolveValue(camelContext, target, key, text,
ignoreCase, fluentBuilder,
allowPrivateSetter, reflection, configurer);
// resolve property placeholders
- if (str instanceof String) {
+ if (str instanceof String strValue) {
// resolve property placeholders
- str = camelContext.resolvePropertyPlaceholders(str.toString());
+ str = camelContext.resolvePropertyPlaceholders(strValue);
}
if (str == null && reference && mandatory && !optional) {
// we could not resolve the reference and this is mandatory
@@ -649,8 +648,7 @@ public final class PropertyBindingSupport {
// special for reference (we should not do this for options that are
String type)
// this is only required for reflection (as configurer does this
automatic in a more safe way)
- if (value instanceof String) {
- String str = value.toString();
+ if (value instanceof String str) {
if (reference && isReferenceParameter(str)) {
Object bean = CamelContextHelper.lookup(context,
str.substring(1));
if (bean != null) {
@@ -710,14 +708,14 @@ public final class PropertyBindingSupport {
String undashKey = undashKey(key);
Object obj = null;
- if (configurer instanceof PropertyConfigurerGetter) {
- obj = ((PropertyConfigurerGetter)
configurer).getOptionValue(target, undashKey, ignoreCase);
+ if (configurer instanceof PropertyConfigurerGetter
propertyConfigurerGetter) {
+ obj = propertyConfigurerGetter.getOptionValue(target, undashKey,
ignoreCase);
}
if (obj == null) {
// it was supposed to be a list or map, but its null, so let's
create a new list or map and set it automatically
Class<?> returnType = null;
- if (configurer instanceof PropertyConfigurerGetter) {
- returnType = ((PropertyConfigurerGetter)
configurer).getOptionType(undashKey, true);
+ if (configurer instanceof PropertyConfigurerGetter
propertyConfigurerGetter) {
+ returnType = propertyConfigurerGetter.getOptionType(undashKey,
true);
}
if (returnType == null) {
return false;
@@ -835,14 +833,13 @@ public final class PropertyBindingSupport {
String undashKey = undashKey(name);
- if (value instanceof String) {
- String str = value.toString();
+ if (value instanceof String str) {
if (str.equals("#autowired")) {
// we should get the type from the setter
Class<?> parameterType = null;
- if (configurer instanceof PropertyConfigurerGetter) {
+ if (configurer instanceof PropertyConfigurerGetter
propertyConfigurerGetter) {
// favour using configurer
- parameterType = ((PropertyConfigurerGetter)
configurer).getOptionType(undashKey, true);
+ parameterType =
propertyConfigurerGetter.getOptionType(undashKey, true);
}
if (parameterType == null && reflection) {
// fallback to reflection
@@ -871,8 +868,7 @@ public final class PropertyBindingSupport {
boolean ignoreCase, boolean fluentBuilder, boolean
allowPrivateSetter,
boolean reflection, PropertyConfigurer configurer)
throws Exception {
- if (value instanceof String) {
- String str = value.toString();
+ if (value instanceof String str) {
if (str.startsWith("#property:")) {
String key = str.substring(10);
// the key may have property placeholder so resolve those first
@@ -900,11 +896,10 @@ public final class PropertyBindingSupport {
throws Exception {
String refName = null;
- if (reference && value instanceof String) {
- String str = value.toString();
+ if (reference && value instanceof String str) {
if (str.startsWith("#bean:")) {
// okay it's a reference so swap to look up this which is
already supported in IntrospectionSupport
- refName = "#" + ((String) value).substring(6);
+ refName = "#" + str.substring(6);
value = null;
} else if (str.equals("#autowired")) {
value = resolveAutowired(context, target, name, value,
ignoreCase, fluentBuilder, allowPrivateSetter, true,
@@ -946,13 +941,13 @@ public final class PropertyBindingSupport {
Object answer = null;
Class<?> type = null;
- if (configurer instanceof PropertyConfigurerGetter) {
- answer = ((PropertyConfigurerGetter)
configurer).getOptionValue(target, undashKey, ignoreCase);
+ if (configurer instanceof PropertyConfigurerGetter
propertyConfigurerGetter) {
+ answer = propertyConfigurerGetter.getOptionValue(target,
undashKey, ignoreCase);
}
if (answer != null) {
type = answer.getClass();
- } else if (configurer instanceof PropertyConfigurerGetter) {
- type = ((PropertyConfigurerGetter)
configurer).getOptionType(undashKey, true);
+ } else if (configurer instanceof PropertyConfigurerGetter
propertyConfigurerGetter) {
+ type = propertyConfigurerGetter.getOptionType(undashKey, true);
}
if (answer == null && type == null) {
@@ -1265,8 +1260,7 @@ public final class PropertyBindingSupport {
Object param = params[i];
Object val = null;
// special as we may refer to other #bean or #type in the
parameter
- if (param instanceof String) {
- String str = param.toString();
+ if (param instanceof String str) {
if (str.startsWith("#")) {
Object bean = resolveBean(camelContext, param);
if (bean != null) {
@@ -1275,8 +1269,8 @@ public final class PropertyBindingSupport {
}
}
// unquote text
- if (val instanceof String) {
- val = StringHelper.removeLeadingAndEndingQuotes((String)
val);
+ if (val instanceof String strVal) {
+ val = StringHelper.removeLeadingAndEndingQuotes(strVal);
}
if (val != null) {
val =
camelContext.getTypeConverter().tryConvertTo(paramType, val);
@@ -1366,8 +1360,7 @@ public final class PropertyBindingSupport {
Object param = params[i];
Object val = null;
// special as we may refer to other #bean or #type in the
parameter
- if (param instanceof String) {
- String str = param.toString();
+ if (param instanceof String str) {
if (str.startsWith("#")) {
Object bean = resolveBean(camelContext, param);
if (bean != null) {
@@ -1376,8 +1369,8 @@ public final class PropertyBindingSupport {
}
}
// unquote text
- if (val instanceof String) {
- val = StringHelper.removeLeadingAndEndingQuotes((String)
val);
+ if (val instanceof String strVal) {
+ val = StringHelper.removeLeadingAndEndingQuotes(strVal);
}
if (val != null) {
val =
camelContext.getTypeConverter().tryConvertTo(paramType, val);
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/PropertyConfigurerHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/PropertyConfigurerHelper.java
index dc201f28f80..3e95a167c47 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/PropertyConfigurerHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/PropertyConfigurerHelper.java
@@ -46,10 +46,10 @@ public final class PropertyConfigurerHelper {
PropertyConfigurer configurer = null;
- if (target instanceof Component) {
+ if (target instanceof Component component) {
// the component needs to be initialized to have the configurer
ready
ServiceHelper.initService(target);
- configurer = ((Component) target).getComponentPropertyConfigurer();
+ configurer = component.getComponentPropertyConfigurer();
}
if (configurer == null) {
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/ResolverHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/ResolverHelper.java
index 75ad08ae9c6..23cdf2e40b3 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/ResolverHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/ResolverHelper.java
@@ -60,8 +60,8 @@ public final class ResolverHelper {
Object bean
= lookupInRegistry(context, Component.class, false,
exceptionHandler, name, name + COMPONENT_FALLBACK_SUFFIX);
if (bean != null) {
- if (bean instanceof Component) {
- return (Component) bean;
+ if (bean instanceof Component component) {
+ return component;
} else {
// let's use Camel's type conversion mechanism to convert
things like CamelContext
// and other types into a valid Component
@@ -86,8 +86,8 @@ public final class ResolverHelper {
CamelContext context, String name, LookupExceptionHandler
exceptionHandler) {
Object bean = lookupInRegistry(context, DataFormat.class, false,
exceptionHandler, name,
name + DATA_FORMAT_FALLBACK_SUFFIX);
- if (bean instanceof DataFormat) {
- return (DataFormat) bean;
+ if (bean instanceof DataFormat dataFormat) {
+ return dataFormat;
}
if (bean != null) {
@@ -104,8 +104,8 @@ public final class ResolverHelper {
CamelContext context, String name, LookupExceptionHandler
exceptionHandler) {
Object bean = lookupInRegistry(context, DataFormatFactory.class,
false, exceptionHandler, name,
name + DATA_FORMAT_FACTORY_FALLBACK_SUFFIX);
- if (bean instanceof DataFormatFactory) {
- return (DataFormatFactory) bean;
+ if (bean instanceof DataFormatFactory dataFormatFactory) {
+ return dataFormatFactory;
}
if (bean != null) {
@@ -121,8 +121,8 @@ public final class ResolverHelper {
public static Language lookupLanguageInRegistryWithFallback(
CamelContext context, String name, LookupExceptionHandler
exceptionHandler) {
Object bean = lookupInRegistry(context, Language.class, false,
exceptionHandler, name, name + LANGUAGE_FALLBACK_SUFFIX);
- if (bean instanceof Language) {
- return (Language) bean;
+ if (bean instanceof Language language) {
+ return language;
}
if (bean != null) {
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/RouteVariableRepository.java
b/core/camel-support/src/main/java/org/apache/camel/support/RouteVariableRepository.java
index 31cad8d90da..5460e4f1b07 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/RouteVariableRepository.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/RouteVariableRepository.java
@@ -182,8 +182,7 @@ public final class RouteVariableRepository extends
ServiceSupport implements Bro
// check if body is already cached
if (body == null) {
return null;
- } else if (body instanceof StreamCache) {
- StreamCache sc = (StreamCache) body;
+ } else if (body instanceof StreamCache sc) {
// reset so the cache is ready to be used before processing
sc.reset();
return sc;
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java
b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java
index 97d38d0f5b9..658f7896d25 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java
@@ -270,8 +270,8 @@ public abstract class ScheduledPollConsumer extends
DefaultConsumer
errorCounter.incrementAndGet();
lastError = cause;
// enrich last error with http response code if possible
- if (cause instanceof HttpResponseAware) {
- int code = ((HttpResponseAware) cause).getHttpResponseCode();
+ if (cause instanceof HttpResponseAware httpResponseAware) {
+ int code = httpResponseAware.getHttpResponseCode();
if (code > 0) {
addLastErrorDetail(HealthCheck.HTTP_RESPONSE_CODE, code);
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java
b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java
index 2f3976d3db0..7aa12a21182 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java
@@ -153,16 +153,15 @@ public abstract class ScheduledPollEndpoint extends
DefaultEndpoint {
e);
}
} else if (!"none".equals(schedulerKey)) {
- if (schedulerKey instanceof String) {
- String str = schedulerKey.toString();
+ if (schedulerKey instanceof String str) {
// must refer to a custom scheduler by the given name
if (EndpointHelper.isReferenceParameter(str)) {
str = str.substring(1);
}
consumerScheduler =
CamelContextHelper.mandatoryLookup(getCamelContext(), str,
ScheduledPollConsumerScheduler.class);
- } else if (schedulerKey instanceof
ScheduledPollConsumerScheduler) {
- consumerScheduler = (ScheduledPollConsumerScheduler)
schedulerKey;
+ } else if (schedulerKey instanceof
ScheduledPollConsumerScheduler scheduler) {
+ consumerScheduler = scheduler;
} else {
throw new IllegalArgumentException(
"Scheduler must either be a reference to a custom
scheduler or an ScheduledPollConsumerScheduler type, was: "
@@ -173,8 +172,7 @@ public abstract class ScheduledPollEndpoint extends
DefaultEndpoint {
}
protected void doConfigureConsumer(Consumer consumer) {
- if (consumer instanceof ScheduledPollConsumer) {
- ScheduledPollConsumer spc = (ScheduledPollConsumer) consumer;
+ if (consumer instanceof ScheduledPollConsumer spc) {
spc.setBackoffErrorThreshold(backoffErrorThreshold);
spc.setBackoffIdleThreshold(backoffIdleThreshold);
spc.setBackoffMultiplier(backoffMultiplier);
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/SupplierRegistry.java
b/core/camel-support/src/main/java/org/apache/camel/support/SupplierRegistry.java
index 3712134159d..24588f89cc6 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/SupplierRegistry.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/SupplierRegistry.java
@@ -43,18 +43,18 @@ public class SupplierRegistry extends SimpleRegistry {
}
Object answer = map.get(type);
- if (answer instanceof Supplier) {
+ if (answer instanceof Supplier<?> supplier) {
// okay then eval the supplier to get the actual value
- answer = ((Supplier<?>) answer).get();
+ answer = supplier.get();
}
if (answer == null) {
// no direct type match then check if assignable
for (Map.Entry<Class<?>, Object> entry : map.entrySet()) {
if (type.isAssignableFrom(entry.getKey())) {
Object value = entry.getValue();
- if (value instanceof Supplier) {
+ if (value instanceof Supplier<?> supplier) {
// okay then eval the supplier to get the actual value
- value = ((Supplier<?>) value).get();
+ value = supplier.get();
}
answer = value;
break;
@@ -66,9 +66,9 @@ public class SupplierRegistry extends SimpleRegistry {
for (Map.Entry<Class<?>, Object> entry : map.entrySet()) {
if (Object.class == entry.getKey()) {
Object value = entry.getValue();
- if (value instanceof Supplier) {
+ if (value instanceof Supplier<?> supplier) {
// okay then eval the supplier to get the actual value
- value = ((Supplier<?>) value).get();
+ value = supplier.get();
}
if (type.isInstance(value)) {
answer = value;
@@ -97,9 +97,9 @@ public class SupplierRegistry extends SimpleRegistry {
for (Map.Entry<Class<?>, Object> subEntry :
entry.getValue().entrySet()) {
if (type.isAssignableFrom(subEntry.getKey())) {
Object value = subEntry.getValue();
- if (value instanceof Supplier) {
+ if (value instanceof Supplier<?> supplier) {
// okay then eval the supplier to get the actual value
- value = ((Supplier<?>) value).get();
+ value = supplier.get();
}
result.add(type.cast(value));
}
@@ -115,9 +115,9 @@ public class SupplierRegistry extends SimpleRegistry {
for (Map.Entry<Class<?>, Object> subEntry :
entry.getValue().entrySet()) {
if (type.isAssignableFrom(subEntry.getKey())) {
Object value = subEntry.getValue();
- if (value instanceof Supplier) {
+ if (value instanceof Supplier<?> supplier) {
// okay then eval the supplier to get the actual value
- value = ((Supplier<?>) value).get();
+ value = supplier.get();
}
result.put(entry.getKey(), type.cast(value));
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java
b/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java
index ac696463421..a0b156baa96 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java
@@ -2121,8 +2121,8 @@ public class ExpressionBuilder {
boolean constantsOnly = true;
for (Expression expression : expressions) {
expression.init(context);
- if (expression instanceof ConstantExpressionAdapter) {
- Object value = ((ConstantExpressionAdapter)
expression).getValue();
+ if (expression instanceof ConstantExpressionAdapter
constantExpressionAdapter) {
+ Object value =
constantExpressionAdapter.getValue();
preprocessedExpression.add(value.toString());
} else {
preprocessedExpression.add(expression);
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/builder/OutputStreamBuilder.java
b/core/camel-support/src/main/java/org/apache/camel/support/builder/OutputStreamBuilder.java
index dbed9d5d46d..16b49c6ba89 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/builder/OutputStreamBuilder.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/builder/OutputStreamBuilder.java
@@ -83,8 +83,8 @@ public final class OutputStreamBuilder extends OutputStream {
* if stream caching is enabled, otherwise byte[].
*/
public Object build() throws IOException {
- if (outputStream instanceof CachedOutputStream) {
- return ((CachedOutputStream) outputStream).newStreamCache();
+ if (outputStream instanceof CachedOutputStream cachedOutputStream) {
+ return cachedOutputStream.newStreamCache();
}
return ((ByteArrayOutputStream) outputStream).toByteArray();
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/builder/ValueBuilder.java
b/core/camel-support/src/main/java/org/apache/camel/support/builder/ValueBuilder.java
index 63687baefad..b787bc3b9ed 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/builder/ValueBuilder.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/builder/ValueBuilder.java
@@ -43,8 +43,8 @@ public class ValueBuilder implements Expression, Predicate {
@Override
public void initPredicate(CamelContext context) {
- if (expression instanceof Predicate) {
- ((Predicate) expression).initPredicate(context);
+ if (expression instanceof Predicate predicate) {
+ predicate.initPredicate(context);
} else {
expression.init(context);
}
@@ -57,8 +57,8 @@ public class ValueBuilder implements Expression, Predicate {
@Override
public boolean matches(Exchange exchange) {
- if (expression instanceof Predicate) {
- return ((Predicate) expression).matches(exchange);
+ if (expression instanceof Predicate predicate) {
+ return predicate.matches(exchange);
}
return PredicateBuilder.toPredicate(getExpression()).matches(exchange);
}
@@ -313,8 +313,8 @@ public class ValueBuilder implements Expression, Predicate {
}
protected Expression asExpression(Object value) {
- if (value instanceof Expression) {
- return (Expression) value;
+ if (value instanceof Expression expression) {
+ return expression;
} else {
return ExpressionBuilder.constantExpression(value);
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/cache/DefaultProducerCache.java
b/core/camel-support/src/main/java/org/apache/camel/support/cache/DefaultProducerCache.java
index b0a8b7bf185..e5a0c299e18 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/cache/DefaultProducerCache.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/cache/DefaultProducerCache.java
@@ -216,8 +216,8 @@ public class DefaultProducerCache extends ServiceSupport
implements ProducerCach
CompletableFuture<Exchange> future = f != null ? f : new
CompletableFuture<>();
AsyncProducerCallback cb = (p, e, c) ->
asyncDispatchExchange(endpoint, p, resultProcessor, e, c);
try {
- if (processor instanceof AsyncProcessor) {
- ((AsyncProcessor) processor).process(exchange,
+ if (processor instanceof AsyncProcessor asyncProcessor) {
+ asyncProcessor.process(exchange,
doneSync -> doInAsyncProducer(endpoint, exchange, ds
-> future.complete(exchange), cb));
} else {
if (processor != null) {
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java
b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java
index ca0a3da6182..b1da635c2b7 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiComponent.java
@@ -153,8 +153,7 @@ public abstract class AbstractApiComponent<E extends
Enum<E> & ApiName, T, S ext
PropertyConfigurer configurer =
PluginHelper.getConfigurerResolver(getCamelContext())
.resolvePropertyConfigurer(configuration.getClass().getName(),
getCamelContext());
// use reflection free configurer (if possible)
- if (configurer instanceof ExtendedPropertyConfigurerGetter) {
- ExtendedPropertyConfigurerGetter getter =
(ExtendedPropertyConfigurerGetter) configurer;
+ if (configurer instanceof ExtendedPropertyConfigurerGetter getter)
{
for (String key :
getter.getAllOptions(configuration).keySet()) {
Object value = getter.getOptionValue(configuration, key,
true);
if (value != null) {
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiEndpoint.java
b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiEndpoint.java
index 5e332aa688b..d8bab90c22b 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiEndpoint.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiEndpoint.java
@@ -192,9 +192,9 @@ public abstract class AbstractApiEndpoint<E extends
ApiName, T>
@Override
protected void configureConsumer(Consumer consumer) throws Exception {
super.configureConsumer(consumer);
- if (getConfiguration() instanceof AbstractApiConfiguration && consumer
instanceof AbstractApiConsumer) {
+ if (getConfiguration() instanceof AbstractApiConfiguration config &&
consumer instanceof AbstractApiConsumer) {
((AbstractApiConsumer<?, ?>) consumer)
- .setSplitResult(((AbstractApiConfiguration)
getConfiguration()).isSplitResult());
+ .setSplitResult(config.isSplitResult());
}
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiProducer.java
b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiProducer.java
index cdf426705b7..9d2fdfc13e2 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiProducer.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/component/AbstractApiProducer.java
@@ -175,8 +175,7 @@ public abstract class AbstractApiProducer<E extends Enum<E>
& ApiName, T>
try {
// attempt to find out type via configurer so we avoid
using reflection
PropertyConfigurer configurer =
endpoint.getComponent().getEndpointPropertyConfigurer();
- if (configurer instanceof PropertyConfigurerGetter) {
- PropertyConfigurerGetter getter =
(PropertyConfigurerGetter) configurer;
+ if (configurer instanceof PropertyConfigurerGetter getter)
{
Class<?> type = getter.getOptionType(inBodyProperty,
true);
if (type != null) {
value =
endpoint.getCamelContext().getTypeConverter().mandatoryConvertTo(type,
exchange, value);
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiConsumerHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiConsumerHelper.java
index ddbb2664d5e..5bba302aa1a 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiConsumerHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiConsumerHelper.java
@@ -110,10 +110,10 @@ public final class ApiConsumerHelper {
}
return size;
- } else if (results instanceof Iterable) {
+ } else if (results instanceof Iterable<?> iterable) {
// Optimized for iterable
int size = 0;
- for (Object singleResult : (Iterable<?>) results) {
+ for (Object singleResult : iterable) {
processResult(consumer, result, singleResult);
size++;
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodHelper.java
index e11889f374b..d0faa3f25f5 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodHelper.java
@@ -485,12 +485,11 @@ public final class ApiMethodHelper<T extends Enum<T> &
ApiMethod> {
if (value != null && types[index].isArray()) {
Class<?> type = types[index];
- if (value instanceof Collection) {
+ if (value instanceof Collection<?> collection) {
// convert collection to array
- Collection<?> collection = (Collection<?>) value;
Object array = Array.newInstance(type.getComponentType(),
collection.size());
- if (array instanceof Object[]) {
- collection.toArray((Object[]) array);
+ if (array instanceof Object[] objects) {
+ collection.toArray(objects);
} else {
int i = 0;
for (Object el : collection) {
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodPropertiesHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodPropertiesHelper.java
index 2ad2be9c693..a9dbfb71a7f 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodPropertiesHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/component/ApiMethodPropertiesHelper.java
@@ -62,8 +62,7 @@ public abstract class ApiMethodPropertiesHelper<C> {
// use reflection free configurer (if possible)
PropertyConfigurer configurer =
PluginHelper.getConfigurerResolver(context)
.resolvePropertyConfigurer(componentConfiguration.getName(),
context);
- if (configurer instanceof ExtendedPropertyConfigurerGetter) {
- ExtendedPropertyConfigurerGetter getter =
(ExtendedPropertyConfigurerGetter) configurer;
+ if (configurer instanceof ExtendedPropertyConfigurerGetter getter) {
Set<String> names = getter.getAllOptions(null).keySet();
for (String name : names) {
// lower case the first letter which is what the properties
map expects
@@ -109,8 +108,8 @@ public abstract class ApiMethodPropertiesHelper<C> {
PropertyConfigurer configurer =
PluginHelper.getConfigurerResolver(context)
.resolvePropertyConfigurer(endpointConfiguration.getClass().getName(), context);
// use reflection free configurer (if possible)
- if (configurer instanceof ExtendedPropertyConfigurerGetter) {
- useGetters(endpointConfiguration, properties,
(ExtendedPropertyConfigurerGetter) configurer);
+ if (configurer instanceof ExtendedPropertyConfigurerGetter getter) {
+ useGetters(endpointConfiguration, properties, getter);
} else {
PluginHelper.getBeanIntrospection(context).getProperties(endpointConfiguration,
properties,
null, false);
@@ -136,8 +135,7 @@ public abstract class ApiMethodPropertiesHelper<C> {
PropertyConfigurer configurer =
PluginHelper.getConfigurerResolver(context)
.resolvePropertyConfigurer(endpointConfiguration.getClass().getName(), context);
// use reflection free configurer (if possible)
- if (configurer instanceof ExtendedPropertyConfigurerGetter) {
- ExtendedPropertyConfigurerGetter getter =
(ExtendedPropertyConfigurerGetter) configurer;
+ if (configurer instanceof ExtendedPropertyConfigurerGetter getter) {
Set<String> names =
getter.getAllOptions(endpointConfiguration).keySet();
for (String name : names) {
// lower case the first letter which is what the properties
map expects
@@ -157,8 +155,8 @@ public abstract class ApiMethodPropertiesHelper<C> {
PropertyConfigurer configurer =
PluginHelper.getConfigurerResolver(context)
.resolvePropertyConfigurer(endpointConfiguration.getClass().getName(), context);
// use reflection free configurer (if possible)
- if (configurer instanceof ExtendedPropertyConfigurerGetter) {
- useGetters(endpointConfiguration, properties,
(ExtendedPropertyConfigurerGetter) configurer);
+ if (configurer instanceof ExtendedPropertyConfigurerGetter getter) {
+ useGetters(endpointConfiguration, properties, getter);
} else {
PluginHelper.getBeanIntrospection(context).getProperties(endpointConfiguration,
properties,
null, false);
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/component/EndpointUriFactorySupport.java
b/core/camel-support/src/main/java/org/apache/camel/support/component/EndpointUriFactorySupport.java
index 26a78dfc8ab..9b72a64e93d 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/component/EndpointUriFactorySupport.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/component/EndpointUriFactorySupport.java
@@ -87,8 +87,7 @@ public abstract class EndpointUriFactorySupport implements
CamelContextAware, En
Map<String, Object> map = new TreeMap<>(parameters);
for (String secretParameter : secretPropertyNames()) {
Object val = map.get(secretParameter);
- if (val instanceof String) {
- String answer = (String) val;
+ if (val instanceof String answer) {
if (!answer.startsWith("#") && !answer.startsWith("RAW(")) {
map.put(secretParameter, "RAW(" + val + ")");
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/component/PropertyConfigurerSupport.java
b/core/camel-support/src/main/java/org/apache/camel/support/component/PropertyConfigurerSupport.java
index 984c1d954a6..80d6854da1a 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/component/PropertyConfigurerSupport.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/component/PropertyConfigurerSupport.java
@@ -86,8 +86,7 @@ public abstract class PropertyConfigurerSupport {
}
// special for boolean values with string values as we only want to
accept "true" or "false"
- if ((type == Boolean.class || type == boolean.class) && value
instanceof String) {
- String text = (String) value;
+ if ((type == Boolean.class || type == boolean.class) && value
instanceof String text) {
if (!MAGIC_VALUE.equals(value) && !text.equalsIgnoreCase("true")
&& !text.equalsIgnoreCase("false")) {
throw new IllegalArgumentException(
"Cannot convert the String value: " + value + " to
type: " + type
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/jndi/CamelInitialContextFactory.java
b/core/camel-support/src/main/java/org/apache/camel/support/jndi/CamelInitialContextFactory.java
index 34856bd01b7..1fee189d927 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/jndi/CamelInitialContextFactory.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/jndi/CamelInitialContextFactory.java
@@ -45,8 +45,8 @@ public class CamelInitialContextFactory implements
InitialContextFactory {
try {
return new JndiContext(CastUtils.cast(environment, String.class,
Object.class));
} catch (Exception e) {
- if (e instanceof NamingException) {
- throw (NamingException) e;
+ if (e instanceof NamingException namingException) {
+ throw namingException;
}
NamingException exception = new NamingException(e.getMessage());
exception.initCause(e);
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/jndi/JndiContext.java
b/core/camel-support/src/main/java/org/apache/camel/support/jndi/JndiContext.java
index f09c4ce3a6c..40cfd27fe8b 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/jndi/JndiContext.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/jndi/JndiContext.java
@@ -206,8 +206,7 @@ public class JndiContext implements Context, Serializable {
}
}
}
- if (result instanceof LinkRef) {
- LinkRef ref = (LinkRef) result;
+ if (result instanceof LinkRef ref) {
result = lookup(ref.getLinkName());
}
if (result instanceof Reference) {
@@ -219,12 +218,12 @@ public class JndiContext implements Context, Serializable
{
throw (NamingException) new NamingException("could not look up
: " + name).initCause(e);
}
}
- if (result instanceof JndiContext) {
+ if (result instanceof JndiContext jndiContext) {
String prefix = getNameInNamespace();
if (!prefix.isEmpty()) {
prefix = prefix + SEPARATOR;
}
- result = new JndiContext((JndiContext) result, environment, prefix
+ name);
+ result = new JndiContext(jndiContext, environment, prefix + name);
}
return result;
}
@@ -258,8 +257,8 @@ public class JndiContext implements Context, Serializable {
Object o = lookup(name);
if (o == this) {
return CastUtils.cast(new ListEnumeration());
- } else if (o instanceof Context) {
- return ((Context) o).list("");
+ } else if (o instanceof Context context) {
+ return context.list("");
} else {
throw new NotContextException();
}
@@ -270,8 +269,8 @@ public class JndiContext implements Context, Serializable {
Object o = lookup(name);
if (o == this) {
return CastUtils.cast(new ListBindingEnumeration());
- } else if (o instanceof Context) {
- return ((Context) o).listBindings("");
+ } else if (o instanceof Context context) {
+ return context.listBindings("");
} else {
throw new NotContextException();
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/management/DefaultManagementMBeanAssembler.java
b/core/camel-support/src/main/java/org/apache/camel/support/management/DefaultManagementMBeanAssembler.java
index c033f0071ea..b2ffdb525d2 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/management/DefaultManagementMBeanAssembler.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/management/DefaultManagementMBeanAssembler.java
@@ -58,9 +58,9 @@ public class DefaultManagementMBeanAssembler extends
ServiceSupport implements M
Object custom = null;
// prefer to use the managed instance if it has been annotated with
JMX annotations
- if (obj instanceof ManagedInstance) {
+ if (obj instanceof ManagedInstance managedInstance) {
// there may be a custom embedded instance which have additional
methods
- custom = ((ManagedInstance) obj).getInstance();
+ custom = managedInstance.getInstance();
if (custom != null &&
ObjectHelper.hasAnnotation(custom.getClass().getAnnotations(),
ManagedResource.class)) {
LOG.trace("Assembling MBeanInfo for: {} from custom
@ManagedResource object: {}", name, custom);
// get the mbean info into different groups (mbi = both,
standard = standard out of the box mbi)
@@ -110,8 +110,8 @@ public class DefaultManagementMBeanAssembler extends
ServiceSupport implements M
}
// Allows the managed object to send notifications
- if (obj instanceof NotificationSenderAware) {
- ((NotificationSenderAware) obj).setNotificationSender(new
NotificationSenderAdapter(mbean));
+ if (obj instanceof NotificationSenderAware notificationSenderAware) {
+ notificationSenderAware.setNotificationSender(new
NotificationSenderAdapter(mbean));
}
return mbean;
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/processor/RestBindingAdvice.java
b/core/camel-support/src/main/java/org/apache/camel/support/processor/RestBindingAdvice.java
index cccd750610b..9c5db6b4fc9 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/processor/RestBindingAdvice.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/processor/RestBindingAdvice.java
@@ -245,8 +245,8 @@ public class RestBindingAdvice extends ServiceSupport
implements CamelInternalPr
// so force reading the body as a String which we can work with
body = MessageHelper.extractBodyAsString(exchange.getIn());
if (ObjectHelper.isNotEmpty(body)) {
- if (exchange.getIn() instanceof DataTypeAware) {
- ((DataTypeAware) exchange.getIn()).setBody(body, new
DataType(isJson ? "json" : "xml"));
+ if (exchange.getIn() instanceof DataTypeAware
dataTypeAware) {
+ dataTypeAware.setBody(body, new DataType(isJson ?
"json" : "xml"));
} else {
exchange.getIn().setBody(body);
}
@@ -468,8 +468,8 @@ public class RestBindingAdvice extends ServiceSupport
implements CamelInternalPr
private void setOutputDataType(Exchange exchange, DataType type) {
Message target = exchange.getMessage();
- if (target instanceof DataTypeAware) {
- ((DataTypeAware) target).setDataType(type);
+ if (target instanceof DataTypeAware dataTypeAware) {
+ dataTypeAware.setDataType(type);
}
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/resume/ResumeStrategyHelper.java
b/core/camel-support/src/main/java/org/apache/camel/support/resume/ResumeStrategyHelper.java
index cd8712caf18..86d06b33ca9 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/resume/ResumeStrategyHelper.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/resume/ResumeStrategyHelper.java
@@ -82,11 +82,11 @@ public final class ResumeStrategyHelper {
return;
}
- if (resumeAdapter instanceof ResumeActionAware) {
+ if (resumeAdapter instanceof ResumeActionAware resumeActionAware) {
ResumeAction action = (ResumeAction)
context.getRegistry().lookupByName(actionName);
ObjectHelper.notNull(action, "The resume action cannot be null",
on);
- ((ResumeActionAware) resumeAdapter).setResumeAction(action);
+ resumeActionAware.setResumeAction(action);
}
resumeAdapter.resume();