You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/08/17 09:16:11 UTC
[camel] branch main updated: (chores) cleanup duplicated decapitalization code (#11131)
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 64b08c44f8e (chores) cleanup duplicated decapitalization code (#11131)
64b08c44f8e is described below
commit 64b08c44f8e52f1fd608ed0de78f48971c99b69f
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Thu Aug 17 11:16:04 2023 +0200
(chores) cleanup duplicated decapitalization code (#11131)
---
.../camel/impl/engine/IntrospectionSupport.java | 6 ++----
.../java/org/apache/camel/util/ObjectHelper.java | 2 +-
.../java/org/apache/camel/util/StringHelper.java | 22 ++++++++++++++++++++++
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/IntrospectionSupport.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/IntrospectionSupport.java
index 675599a14dd..2b7dc7ffba3 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/IntrospectionSupport.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/IntrospectionSupport.java
@@ -158,11 +158,9 @@ final class IntrospectionSupport {
String name = method.getName();
if (name.startsWith("get")) {
- name = name.substring(3);
- name = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1);
+ name = StringHelper.decapitalize(name.substring(3));
} else if (name.startsWith("is")) {
- name = name.substring(2);
- name = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1);
+ name = StringHelper.decapitalize(name.substring(2));
}
return name;
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java
index eb37a1e4384..b3cee67a36a 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java
@@ -1059,7 +1059,7 @@ public final class ObjectHelper {
public static String getPropertyName(Method method) {
String propertyName = method.getName();
if (propertyName.startsWith("set") && method.getParameterCount() == 1) {
- propertyName = propertyName.substring(3, 4).toLowerCase(Locale.ENGLISH) + propertyName.substring(4);
+ propertyName = StringHelper.decapitalize(propertyName.substring(3));
}
return propertyName;
}
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
index 7c8e7e053b7..e0db1261d2f 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/StringHelper.java
@@ -507,6 +507,28 @@ public final class StringHelper {
return new String(chars);
}
+ /**
+ * De-capitalize the string (lower case first character)
+ *
+ * @param text the string
+ * @return the string decapitalized (lower case first character)
+ */
+ public static String decapitalize(final String text) {
+ if (text == null) {
+ return null;
+ }
+
+ int length = text.length();
+ final char[] chars = new char[length];
+ text.getChars(0, length, chars, 0);
+
+ // We are OK with the limitations of Character.toLowerCase. The symbols and ideographs
+ // for which it does not return the lower case value should not be used here (this is
+ // mostly used to convert part of setters/getters to properties)
+ chars[0] = Character.toLowerCase(chars[0]);
+ return new String(chars);
+ }
+
/**
* Converts the string from dash format into camel case (hello-great-world -> helloGreatWorld)
*