commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pascalschumac...@apache.org
Subject [lang] Use foreach loop for arrays (closes #245)
Date Fri, 24 Feb 2017 21:52:19 GMT
Repository: commons-lang
Updated Branches:
  refs/heads/master 36b00f803 -> 44516f77e


Use foreach loop for arrays (closes #245)

Since the project no longer supports Java versions older than 6, it's
safe to use the enhanced for loop syntax introduced in Java 5.

This patch employs this syntax where possible to clean up the code.


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/44516f77
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/44516f77
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/44516f77

Branch: refs/heads/master
Commit: 44516f77ecd06aa818263ec31e150bab3edd956b
Parents: 36b00f8
Author: Allon Mureinik <amureini@redhat.com>
Authored: Fri Feb 24 20:50:10 2017 +0200
Committer: pascalschumacher <pascalschumacher@gmx.net>
Committed: Fri Feb 24 22:52:13 2017 +0100

----------------------------------------------------------------------
 src/main/java/org/apache/commons/lang3/CharSet.java   |  5 ++---
 .../java/org/apache/commons/lang3/CharSetUtils.java   |  7 +++----
 .../java/org/apache/commons/lang3/StringUtils.java    | 14 ++++++--------
 .../org/apache/commons/lang3/reflect/MethodUtils.java |  8 ++++----
 4 files changed, 15 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/44516f77/src/main/java/org/apache/commons/lang3/CharSet.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/CharSet.java b/src/main/java/org/apache/commons/lang3/CharSet.java
index cf3244c..150f850 100644
--- a/src/main/java/org/apache/commons/lang3/CharSet.java
+++ b/src/main/java/org/apache/commons/lang3/CharSet.java
@@ -175,9 +175,8 @@ public class CharSet implements Serializable {
      */
     protected CharSet(final String... set) {
         super();
-        final int sz = set.length;
-        for (int i = 0; i < sz; i++) {
-            add(set[i]);
+        for (String s : set) {
+            add(s);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/44516f77/src/main/java/org/apache/commons/lang3/CharSetUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/CharSetUtils.java b/src/main/java/org/apache/commons/lang3/CharSetUtils.java
index 6284e38..84c1d09 100644
--- a/src/main/java/org/apache/commons/lang3/CharSetUtils.java
+++ b/src/main/java/org/apache/commons/lang3/CharSetUtils.java
@@ -234,10 +234,9 @@ public class CharSetUtils {
         final CharSet chars = CharSet.getInstance(set);
         final StringBuilder buffer = new StringBuilder(str.length());
         final char[] chrs = str.toCharArray();
-        final int sz = chrs.length;
-        for(int i=0; i<sz; i++) {
-            if(chars.contains(chrs[i]) == expect) {
-                buffer.append(chrs[i]);
+        for (char chr : chrs) {
+            if (chars.contains(chr) == expect) {
+                buffer.append(chr);
             }
         }
         return buffer.toString();

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/44516f77/src/main/java/org/apache/commons/lang3/StringUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index 1a0325e..8049850 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -2467,8 +2467,7 @@ public class StringUtils {
         int ret = Integer.MAX_VALUE;
 
         int tmp = 0;
-        for (int i = 0; i < sz; i++) {
-            final CharSequence search = searchStrs[i];
+        for (final CharSequence search : searchStrs) {
             if (search == null) {
                 continue;
             }
@@ -2518,8 +2517,7 @@ public class StringUtils {
         final int sz = searchStrs.length;
         int ret = INDEX_NOT_FOUND;
         int tmp = 0;
-        for (int i = 0; i < sz; i++) {
-            final CharSequence search = searchStrs[i];
+        for (final CharSequence search : searchStrs) {
             if (search == null) {
                 continue;
             }
@@ -7751,14 +7749,14 @@ public class StringUtils {
         // find the min and max string lengths; this avoids checking to make
         // sure we are not exceeding the length of the string each time through
         // the bottom loop.
-        for (int i = 0; i < arrayLen; i++) {
-            if (css[i] == null) {
+        for (CharSequence cs : css) {
+            if (cs == null) {
                 anyStringNull = true;
                 shortestStrLen = 0;
             } else {
                 allStringsNull = false;
-                shortestStrLen = Math.min(css[i].length(), shortestStrLen);
-                longestStrLen = Math.max(css[i].length(), longestStrLen);
+                shortestStrLen = Math.min(cs.length(), shortestStrLen);
+                longestStrLen = Math.max(cs.length(), longestStrLen);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/44516f77/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
index 240de9c..0f94d93 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
@@ -624,14 +624,14 @@ public class MethodUtils {
 
             // Check the implemented interfaces of the parent class
             final Class<?>[] interfaces = cls.getInterfaces();
-            for (int i = 0; i < interfaces.length; i++) {
+            for (Class<?> anInterface : interfaces) {
                 // Is this interface public?
-                if (!Modifier.isPublic(interfaces[i].getModifiers())) {
+                if (!Modifier.isPublic(anInterface.getModifiers())) {
                     continue;
                 }
                 // Does the method exist on this interface?
                 try {
-                    return interfaces[i].getDeclaredMethod(methodName,
+                    return anInterface.getDeclaredMethod(methodName,
                             parameterTypes);
                 } catch (final NoSuchMethodException e) { // NOPMD
                     /*
@@ -640,7 +640,7 @@ public class MethodUtils {
                      */
                 }
                 // Recursively check our parent interfaces
-                final Method method = getAccessibleMethodFromInterfaceNest(interfaces[i],
+                final Method method = getAccessibleMethodFromInterfaceNest(anInterface,
                         methodName, parameterTypes);
                 if (method != null) {
                     return method;


Mime
View raw message