You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bu...@apache.org on 2020/05/19 21:04:23 UTC

[cxf] branch master updated: cxf-rt-frontend-jaxrs: minor InjectionUtils improvements

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1846348  cxf-rt-frontend-jaxrs: minor InjectionUtils improvements
1846348 is described below

commit 1846348f9fff03e91180f79b84957673a5bdbe22
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Wed May 20 00:03:38 2020 +0300

    cxf-rt-frontend-jaxrs: minor InjectionUtils improvements
---
 .../org/apache/cxf/jaxrs/utils/InjectionUtils.java | 32 ++++++++--------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
index a46cd0a..f2204bf 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
@@ -702,8 +702,8 @@ public final class InjectionUtils {
                 }
 
                 if (setter != null && getter != null) {
-                    Class<?> type = null;
-                    Type genericType = null;
+                    final Class<?> type;
+                    final Type genericType;
                     Object paramValue = null;
                     if (setter instanceof Method) {
                         type = Method.class.cast(setter).getParameterTypes()[0];
@@ -766,13 +766,11 @@ public final class InjectionUtils {
         return null;
     }
 
-    // CHECKSTYLE:OFF
     private static Object injectIntoMap(Type genericType,
                                         Annotation[] paramAnns,
                                         MultivaluedMap<String, String> processedValues,
                                         boolean decoded,
                                         ParameterType pathParam, Message message) {
-    // CHECKSTYLE:ON
         ParameterizedType paramType = (ParameterizedType) genericType;
         Class<?> keyType = (Class<?>)paramType.getActualTypeArguments()[0];
         Type secondType = InjectionUtils.getType(paramType.getActualTypeArguments(), 1);
@@ -840,10 +838,10 @@ public final class InjectionUtils {
     private static List<MultivaluedMap<String, String>> processValues(Class<?> type, Type genericType,
                                         MultivaluedMap<String, String> values,
                                         boolean isbean) {
-        List<MultivaluedMap<String, String>> valuesList =
-            new ArrayList<>();
+        final List<MultivaluedMap<String, String>> valuesList;
 
         if (isbean && InjectionUtils.isSupportedCollectionOrArray(type)) {
+            valuesList = new ArrayList<>();
             Class<?> realType = InjectionUtils.getActualType(genericType);
             for (Map.Entry<String, List<String>> entry : values.entrySet()) {
                 String memberKey = entry.getKey();
@@ -894,7 +892,7 @@ public final class InjectionUtils {
                 }
             }
         } else {
-            valuesList.add(values);
+            valuesList = Collections.singletonList(values);
         }
 
         return valuesList;
@@ -945,8 +943,8 @@ public final class InjectionUtils {
      //CHECKSTYLE:ON
         Class<?> type = getCollectionType(rawType);
 
-        Class<?> realType = null;
-        Type realGenericType = null;
+        final Class<?> realType;
+        final Type realGenericType;
         if (rawType.isArray()) {
             realType = rawType.getComponentType();
             realGenericType = realType;
@@ -1009,7 +1007,7 @@ public final class InjectionUtils {
         for (String v : values) {
             String[] segments = v.split("/");
             for (String s : segments) {
-                if (s.length() != 0) {
+                if (!s.isEmpty()) {
                     newValues.add(s);
                 }
             }
@@ -1329,20 +1327,14 @@ public final class InjectionUtils {
                     continue;
                 }
 
-                String propertyName = methodName.substring(minLen);
-                if (propertyName.length() == 1) {
-                    propertyName = propertyName.toLowerCase();
-                } else {
-                    propertyName = propertyName.substring(0, 1).toLowerCase()
-                                   + propertyName.substring(1);
-                }
+                String propertyName = StringUtils.uncapitalize(methodName.substring(minLen));
                 if (baseName.contains(propertyName)
                     || "class".equals(propertyName)
                     || "declaringClass".equals(propertyName)) {
                     continue;
                 }
                 if (!"".equals(baseName)) {
-                    propertyName = baseName + "." + propertyName;
+                    propertyName = baseName + '.' + propertyName;
                 }
 
                 Object value = extractFromMethod(bean, m);
@@ -1354,7 +1346,7 @@ public final class InjectionUtils {
                 } else if (value.getClass().isEnum()) {
                     values.putSingle(propertyName, value.toString());
                 } else if (isSupportedCollectionOrArray(value.getClass())) {
-                    List<Object> theValues = null;
+                    final List<Object> theValues;
                     if (value.getClass().isArray()) {
                         theValues = Arrays.asList((Object[])value);
                     } else if (value instanceof Set) {
@@ -1367,7 +1359,7 @@ public final class InjectionUtils {
                     if (isSupportedMap(m.getGenericReturnType())) {
                         Map<Object, Object> map = CastUtils.cast((Map<?, ?>)value);
                         for (Map.Entry<Object, Object> entry : map.entrySet()) {
-                            values.add(propertyName + "." + entry.getKey().toString(),
+                            values.add(propertyName + '.' + entry.getKey().toString(),
                                        entry.getValue().toString());
                         }
                     }