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

sergeyb 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 f5bb94c  [CXF-7609] Splitting as Stream one of the non-critical paths
     new c14acde  Merge branch 'master' of 
https://gitbox.apache.org/repos/asf/cxf
f5bb94c is described below

commit f5bb94cfddc533af2ad2f1edc3e9f2787ad5a226
Author: Sergey Beryozkin <[email protected]>
AuthorDate: Wed Jan 17 13:56:24 2018 +0000

    [CXF-7609] Splitting as Stream one of the non-critical paths
---
 .../org/apache/cxf/common/util/StringUtils.java    | 25 +++++++++++++---------
 .../org/apache/cxf/jaxrs/utils/JAXRSUtils.java     | 14 ++++++------
 2 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/common/util/StringUtils.java 
b/core/src/main/java/org/apache/cxf/common/util/StringUtils.java
index 94b953a..f53bcb5 100644
--- a/core/src/main/java/org/apache/cxf/common/util/StringUtils.java
+++ b/core/src/main/java/org/apache/cxf/common/util/StringUtils.java
@@ -29,8 +29,10 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.function.Predicate;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Stream;
 
 public final class StringUtils {
     public static final Map<String, Pattern> PATTERN_MAP = new HashMap<>();
@@ -40,23 +42,22 @@ public final class StringUtils {
             PATTERN_MAP.put(p, Pattern.compile(p));
         }
     }
+    private static final Predicate<String> NOT_EMPTY = (String s) -> 
!s.isEmpty();
 
     private StringUtils() {
     }
 
     public static String[] split(String s, String regex) {
-        Pattern p = PATTERN_MAP.get(regex);
-        if (p != null) {
-            return p.split(s);
-        }
-        return s.split(regex);
+        return split(s, regex, 0);
     }
     public static String[] split(String s, String regex, int limit) {
-        Pattern p = PATTERN_MAP.get(regex);
-        if (p != null) {
-            return p.split(s, limit);
-        }
-        return s.split(regex, limit);
+        Pattern p = PATTERN_MAP.getOrDefault(regex, Pattern.compile(regex));
+        return p.split(s, limit);
+    }
+    
+    public static Stream<String> splitAsStream(String s, String regex) {
+        Pattern p = PATTERN_MAP.getOrDefault(regex, Pattern.compile(regex));
+        return p.splitAsStream(s);
     }
 
     public static boolean isFileExist(String file) {
@@ -74,6 +75,10 @@ public final class StringUtils {
         }
         return true;
     }
+    
+    public static Predicate<String> notEmpty() {
+        return NOT_EMPTY;
+    }
 
     public static boolean isEmpty(List<String> list) {
         if (list == null || list.size() == 0) {
diff --git 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
index d75412f..558ca29 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
@@ -45,6 +45,7 @@ import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import java.util.stream.Collectors;
 
 import javax.ws.rs.ClientErrorException;
 import javax.ws.rs.Consumes;
@@ -179,13 +180,12 @@ public final class JAXRSUtils {
 
     public static List<PathSegment> getPathSegments(String thePath, boolean 
decode,
                                                     boolean ignoreLastSlash) {
-        String[] segments = StringUtils.split(thePath, "/");
-        List<PathSegment> theList = new ArrayList<>();
-        for (String path : segments) {
-            if (!StringUtils.isEmpty(path)) {
-                theList.add(new PathSegmentImpl(path, decode));
-            }
-        }
+        List<PathSegment> theList = 
+            StringUtils.splitAsStream(thePath, "/")
+            .filter(StringUtils.notEmpty())
+            .map(p -> new PathSegmentImpl(p, decode))
+            .collect(Collectors.toList());
+        
         int len = thePath.length();
         if (len > 0 && thePath.charAt(len - 1) == '/') {
             String value = ignoreLastSlash ? "" : "/";

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to