This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new d5f7da0  camel-core - optimize
d5f7da0 is described below

commit d5f7da0d31a482861ee94965fb9d9b4b067a5e42
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sun Mar 8 01:26:58 2020 +0100

    camel-core - optimize
---
 .../org/apache/camel/support/ExchangeHelper.java   | 20 ++----
 .../camel/support/ScheduledPollEndpoint.java       |  8 ++-
 .../java/org/apache/camel/util/URIScanner.java     | 79 ++++++++++------------
 .../java/org/apache/camel/util/URISupport.java     |  2 +-
 4 files changed, 46 insertions(+), 63 deletions(-)

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 b9ab1d6..d01946a 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
@@ -212,14 +212,8 @@ public final class ExchangeHelper {
      * @throws TypeConversionException is thrown if error during type 
conversion
      * @throws NoTypeConversionAvailableException} if no type converters 
exists to convert to the given type
      */
-    public static <T> T convertToMandatoryType(Exchange exchange, Class<T> 
type, Object value)
-        throws TypeConversionException, NoTypeConversionAvailableException {
-        CamelContext camelContext = exchange.getContext();
-        TypeConverter converter = camelContext.getTypeConverter();
-        if (converter != null) {
-            return converter.mandatoryConvertTo(type, exchange, value);
-        }
-        throw new NoTypeConversionAvailableException(value, type);
+    public static <T> T convertToMandatoryType(Exchange exchange, Class<T> 
type, Object value) throws TypeConversionException, 
NoTypeConversionAvailableException {
+        return 
exchange.getContext().getTypeConverter().mandatoryConvertTo(type, exchange, 
value);
     }
 
     /**
@@ -229,12 +223,7 @@ public final class ExchangeHelper {
      * @throws org.apache.camel.TypeConversionException is thrown if error 
during type conversion
      */
     public static <T> T convertToType(Exchange exchange, Class<T> type, Object 
value) throws TypeConversionException {
-        CamelContext camelContext = exchange.getContext();
-        TypeConverter converter = camelContext.getTypeConverter();
-        if (converter != null) {
-            return converter.convertTo(type, exchange, value);
-        }
-        return null;
+        return exchange.getContext().getTypeConverter().convertTo(type, 
exchange, value);
     }
 
     /**
@@ -556,7 +545,10 @@ public final class ExchangeHelper {
      * @param exchanges  the exchanges
      * @param exchangeId the exchangeId to find
      * @return matching exchange, or <tt>null</tt> if none found
+     *
+     * @deprecated not in use, to be removed in a future Camel release
      */
+    @Deprecated
     public static Exchange getExchangeById(Iterable<Exchange> exchanges, 
String exchangeId) {
         for (Exchange exchange : exchanges) {
             String id = exchange.getExchangeId();
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 b969f41..21a5164 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
@@ -116,9 +116,11 @@ public abstract class ScheduledPollEndpoint extends 
DefaultEndpoint {
     protected void configureScheduledPollConsumerProperties(Map<String, 
Object> options) {
         // special for scheduled poll consumers as we want to allow end users 
to configure its options
         // from the URI parameters without the consumer. prefix
-        Map<String, Object> schedulerProperties = 
PropertiesHelper.extractProperties(options, "scheduler.");
-        if (!schedulerProperties.isEmpty()) {
-            setSchedulerProperties(schedulerProperties);
+        if (!options.isEmpty()) {
+            Map<String, Object> schedulerProperties = 
PropertiesHelper.extractProperties(options, "scheduler.");
+            if (!schedulerProperties.isEmpty()) {
+                setSchedulerProperties(schedulerProperties);
+            }
         }
 
         // options take precedence
diff --git 
a/core/camel-util/src/main/java/org/apache/camel/util/URIScanner.java 
b/core/camel-util/src/main/java/org/apache/camel/util/URIScanner.java
index 8294512..184d625 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/URIScanner.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/URIScanner.java
@@ -37,25 +37,21 @@ class URIScanner {
     // TODO: when upgrading to JDK11 as minimum then use java.nio.Charset
     private static final String CHARSET = "UTF-8";
 
-    private enum Mode {
-        KEY, VALUE
-    }
-
     private static final char END = '\u0000';
 
     private final StringBuilder key;
     private final StringBuilder value;
-    private Mode mode;
+    private boolean keyMode = true;
     private boolean isRaw;
     private char rawTokenEnd;
 
-    public URIScanner() {
+    URIScanner() {
         this.key = new StringBuilder();
         this.value = new StringBuilder();
     }
 
     private void initState() {
-        this.mode = Mode.KEY;
+        this.keyMode = true;
         this.key.setLength(0);
         this.value.setLength(0);
         this.isRaw = false;
@@ -69,8 +65,6 @@ class URIScanner {
             // use a linked map so the parameters is in the same order
             Map<String, Object> answer = new LinkedHashMap<>();
 
-            initState();
-
             // parse the uri parameters char by char
             int len = uri.length();
             for (int i = 0; i < len; i++) {
@@ -84,44 +78,39 @@ class URIScanner {
                     next = END;
                 }
 
-                switch (mode) {
-                    case KEY:
-                        // if there is a = sign then the key ends and we are 
in value mode
-                        if (ch == '=') {
-                            mode = Mode.VALUE;
-                            continue;
-                        }
-
-                        if (ch != '&') {
-                            // regular char so add it to the key
-                            key.append(ch);
-                        }
-                        break;
-                    case VALUE:
-                        // are we a raw value
-                        isRaw = checkRaw();
-
-                        // if we are in raw mode, then we keep adding until we 
hit the end marker
-                        if (isRaw) {
-                            value.append(ch);
-
-                            if (isAtEnd(ch, next)) {
-                                // raw value end, so add that as a parameter, 
and reset flags
-                                addParameter(answer, useRaw || isRaw);
-                                initState();
-                                // skip to next as we are in raw mode and have 
already added the value
-                                i++;
-                            }
-                            continue;
+                if (keyMode) {
+                    // if there is a = sign then the key ends and we are in 
value mode
+                    if (ch == '=') {
+                        keyMode = false;
+                        continue;
+                    }
+
+                    if (ch != '&') {
+                        // regular char so add it to the key
+                        key.append(ch);
+                    }
+                } else {
+                    // are we a raw value
+                    isRaw = checkRaw();
+
+                    // if we are in raw mode, then we keep adding until we hit 
the end marker
+                    if (isRaw) {
+                        value.append(ch);
+
+                        if (isAtEnd(ch, next)) {
+                            // raw value end, so add that as a parameter, and 
reset flags
+                            addParameter(answer, useRaw || isRaw);
+                            initState();
+                            // skip to next as we are in raw mode and have 
already added the value
+                            i++;
                         }
+                        continue;
+                    }
 
-                        if (ch != '&') {
-                            // regular char so add it to the value
-                            value.append(ch);
-                        }
-                        break;
-                    default:
-                        throw new IllegalStateException("Unknown mode: " + 
mode);
+                    if (ch != '&') {
+                        // regular char so add it to the value
+                        value.append(ch);
+                    }
                 }
 
                 // the & denote parameter is ended
diff --git 
a/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java 
b/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
index 2df3bfc..e2a9ca0 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
@@ -175,7 +175,7 @@ public final class URISupport {
      * @see #RAW_TOKEN_END
      */
     public static Map<String, Object> parseQuery(String uri, boolean useRaw, 
boolean lenient) throws URISyntaxException {
-        if (uri == null || ObjectHelper.isEmpty(uri)) {
+        if (uri == null || uri.isEmpty()) {
             // return an empty map
             return new LinkedHashMap<>(0);
         }

Reply via email to