Repository: commons-lang
Updated Branches:
  refs/heads/master 63d8a025e -> fd680a651


tabs replaced by spaces
new tests added

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

Branch: refs/heads/master
Commit: 06506aecf9e46441d08edab311e19e599d273fab
Parents: a399514
Author: beradrian <beradr...@yahoo.com>
Authored: Mon Mar 23 13:06:03 2015 +0200
Committer: beradrian <beradr...@yahoo.com>
Committed: Tue Apr 28 12:58:11 2015 +0300

----------------------------------------------------------------------
 .../org/apache/commons/lang3/ArrayUtils.java    | 476 +++++++++----------
 .../apache/commons/lang3/ArrayUtilsTest.java    |  18 +-
 2 files changed, 253 insertions(+), 241 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/06506aec/src/main/java/org/apache/commons/lang3/ArrayUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java 
b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
index 8f21726..fb53bf8 100644
--- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
@@ -2043,10 +2043,10 @@ public class ArrayUtils {
             return;
         }
         for (int i = 0; i < len; i++) {
-               byte aux = array[offset1 + i];
-               array[offset1 + i] = array[offset2 + i];
-               array[offset2 + i] = aux;
-       }
+            byte aux = array[offset1 + i];
+            array[offset1 + i] = array[offset2 + i];
+            array[offset2 + i] = aux;
+        }
     }
 
     /**
@@ -2065,10 +2065,10 @@ public class ArrayUtils {
             return;
         }
         for (int i = 0; i < len; i++) {
-               char aux = array[offset1 + i];
-               array[offset1 + i] = array[offset2 + i];
-               array[offset2 + i] = aux;
-       }
+            char aux = array[offset1 + i];
+            array[offset1 + i] = array[offset2 + i];
+            array[offset2 + i] = aux;
+        }
     }
 
     /**
@@ -2087,10 +2087,10 @@ public class ArrayUtils {
             return;
         }
         for (int i = 0; i < len; i++) {
-               double aux = array[offset1 + i];
-               array[offset1 + i] = array[offset2 + i];
-               array[offset2 + i] = aux;
-       }
+            double aux = array[offset1 + i];
+            array[offset1 + i] = array[offset2 + i];
+            array[offset2 + i] = aux;
+        }
     }
 
     /**
@@ -2109,10 +2109,10 @@ public class ArrayUtils {
             return;
         }
         for (int i = 0; i < len; i++) {
-               float aux = array[offset1 + i];
-               array[offset1 + i] = array[offset2 + i];
-               array[offset2 + i] = aux;
-       }
+            float aux = array[offset1 + i];
+            array[offset1 + i] = array[offset2 + i];
+            array[offset2 + i] = aux;
+        }
     }
 
     /**
@@ -2131,10 +2131,10 @@ public class ArrayUtils {
             return;
         }
         for (int i = 0; i < len; i++) {
-               int aux = array[offset1 + i];
-               array[offset1 + i] = array[offset2 + i];
-               array[offset2 + i] = aux;
-       }
+            int aux = array[offset1 + i];
+            array[offset1 + i] = array[offset2 + i];
+            array[offset2 + i] = aux;
+        }
     }
 
     /**
@@ -2153,9 +2153,9 @@ public class ArrayUtils {
             return;
         }
         for (int i = 0; i < len; i++) {
-               long aux = array[offset1 + i];
-               array[offset1 + i] = array[offset2 + i];
-               array[offset2 + i] = aux;
+            long aux = array[offset1 + i];
+            array[offset1 + i] = array[offset2 + i];
+            array[offset2 + i] = aux;
        }
     }
 
@@ -2175,10 +2175,10 @@ public class ArrayUtils {
             return;
         }
         for (int i = 0; i < len; i++) {
-               Object aux = array[offset1 + i];
-               array[offset1 + i] = array[offset2 + i];
-               array[offset2 + i] = aux;
-       }
+            Object aux = array[offset1 + i];
+            array[offset1 + i] = array[offset2 + i];
+            array[offset2 + i] = aux;
+        }
     }
 
    /**
@@ -2197,10 +2197,10 @@ public class ArrayUtils {
             return;
         }
         for (int i = 0; i < len; i++) {
-               short aux = array[offset1 + i];
-               array[offset1 + i] = array[offset2 + i];
-               array[offset2 + i] = aux;
-       }
+            short aux = array[offset1 + i];
+            array[offset1 + i] = array[offset2 + i];
+            array[offset2 + i] = aux;
+        }
     }
 
     // Shift
@@ -2361,35 +2361,35 @@ public class ArrayUtils {
             return;
         }
         if (startIndexInclusive < 0) {
-               startIndexInclusive = 0;
+            startIndexInclusive = 0;
         } 
         if (endIndexExclusive >= array.length) {
-               endIndexExclusive = array.length;
+            endIndexExclusive = array.length;
         }        
         int n = endIndexExclusive - startIndexInclusive;
         if (n <= 1) {
-               return;
+            return;
+        }
+        offset %= n;
+        if (offset < 0) {
+            offset += n;
+        }
+        while (n > 1 && offset > 0) {
+            int n_offset = n - offset;
+            
+            if (offset > n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + n - 
n_offset,  n_offset);
+                n = offset;
+                offset -= n_offset;
+            } else if (offset < n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
+                startIndexInclusive += offset;
+                n = n_offset;
+            } else {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
+                break;
+            }
         }
-       offset %= n;
-       if (offset < 0) {
-               offset += n;
-       }
-               while (n > 1 && offset > 0) {
-                       int n_offset = n - offset;
-                       
-               if (offset > n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n - n_offset,  n_offset);
-                       n = offset;
-                       offset -= n_offset;
-               } else if (offset < n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
-                       startIndexInclusive += offset;
-                       n = n_offset;
-               } else {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
-                       break;
-               }
-               }
     }
 
     /**
@@ -2419,35 +2419,35 @@ public class ArrayUtils {
             return;
         }
         if (startIndexInclusive < 0) {
-               startIndexInclusive = 0;
+            startIndexInclusive = 0;
         } 
         if (endIndexExclusive >= array.length) {
-               endIndexExclusive = array.length;
+            endIndexExclusive = array.length;
         }        
         int n = endIndexExclusive - startIndexInclusive;
         if (n <= 1) {
-               return;
+            return;
+        }
+        offset %= n;
+        if (offset < 0) {
+            offset += n;
+        }
+        while (n > 1 && offset > 0) {
+            int n_offset = n - offset;
+            
+            if (offset > n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + n - 
n_offset,  n_offset);
+                n = offset;
+                offset -= n_offset;
+            } else if (offset < n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
+                startIndexInclusive += offset;
+                n = n_offset;
+            } else {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
+                break;
+            }
         }
-       offset %= n;
-       if (offset < 0) {
-               offset += n;
-       }
-               while (n > 1 && offset > 0) {
-                       int n_offset = n - offset;
-                       
-               if (offset > n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n - n_offset,  n_offset);
-                       n = offset;
-                       offset -= n_offset;
-               } else if (offset < n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
-                       startIndexInclusive += offset;
-                       n = n_offset;
-               } else {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
-                       break;
-               }
-               }
     }
 
     /**
@@ -2477,35 +2477,35 @@ public class ArrayUtils {
             return;
         }
         if (startIndexInclusive < 0) {
-               startIndexInclusive = 0;
+            startIndexInclusive = 0;
         } 
         if (endIndexExclusive >= array.length) {
-               endIndexExclusive = array.length;
+            endIndexExclusive = array.length;
         }        
         int n = endIndexExclusive - startIndexInclusive;
         if (n <= 1) {
-               return;
+            return;
+        }
+        offset %= n;
+        if (offset < 0) {
+            offset += n;
+        }
+        while (n > 1 && offset > 0) {
+            int n_offset = n - offset;
+            
+            if (offset > n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + n - 
n_offset,  n_offset);
+                n = offset;
+                offset -= n_offset;
+            } else if (offset < n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
+                startIndexInclusive += offset;
+                n = n_offset;
+            } else {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
+                break;
+            }
         }
-       offset %= n;
-       if (offset < 0) {
-               offset += n;
-       }
-               while (n > 1 && offset > 0) {
-                       int n_offset = n - offset;
-                       
-               if (offset > n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n - n_offset,  n_offset);
-                       n = offset;
-                       offset -= n_offset;
-               } else if (offset < n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
-                       startIndexInclusive += offset;
-                       n = n_offset;
-               } else {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
-                       break;
-               }
-               }
     }
 
     /**
@@ -2535,35 +2535,35 @@ public class ArrayUtils {
             return;
         }
         if (startIndexInclusive < 0) {
-               startIndexInclusive = 0;
+            startIndexInclusive = 0;
         } 
         if (endIndexExclusive >= array.length) {
-               endIndexExclusive = array.length;
+            endIndexExclusive = array.length;
         }        
         int n = endIndexExclusive - startIndexInclusive;
         if (n <= 1) {
-               return;
+            return;
+        }
+        offset %= n;
+        if (offset < 0) {
+            offset += n;
+        }
+        while (n > 1 && offset > 0) {
+            int n_offset = n - offset;
+            
+            if (offset > n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + n - 
n_offset,  n_offset);
+                n = offset;
+                offset -= n_offset;
+            } else if (offset < n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
+                startIndexInclusive += offset;
+                n = n_offset;
+            } else {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
+                break;
+            }
         }
-       offset %= n;
-       if (offset < 0) {
-               offset += n;
-       }
-               while (n > 1 && offset > 0) {
-                       int n_offset = n - offset;
-                       
-               if (offset > n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n - n_offset,  n_offset);
-                       n = offset;
-                       offset -= n_offset;
-               } else if (offset < n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
-                       startIndexInclusive += offset;
-                       n = n_offset;
-               } else {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
-                       break;
-               }
-               }
     }
 
     /**
@@ -2593,35 +2593,35 @@ public class ArrayUtils {
             return;
         }
         if (startIndexInclusive < 0) {
-               startIndexInclusive = 0;
+            startIndexInclusive = 0;
         } 
         if (endIndexExclusive >= array.length) {
-               endIndexExclusive = array.length;
+            endIndexExclusive = array.length;
         }        
         int n = endIndexExclusive - startIndexInclusive;
         if (n <= 1) {
-               return;
+            return;
+        }
+        offset %= n;
+        if (offset < 0) {
+            offset += n;
+        }
+        while (n > 1 && offset > 0) {
+            int n_offset = n - offset;
+            
+            if (offset > n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + n - 
n_offset,  n_offset);
+                n = offset;
+                offset -= n_offset;
+            } else if (offset < n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
+                startIndexInclusive += offset;
+                n = n_offset;
+            } else {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
+                break;
+            }
         }
-       offset %= n;
-       if (offset < 0) {
-               offset += n;
-       }
-               while (n > 1 && offset > 0) {
-                       int n_offset = n - offset;
-                       
-               if (offset > n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n - n_offset,  n_offset);
-                       n = offset;
-                       offset -= n_offset;
-               } else if (offset < n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
-                       startIndexInclusive += offset;
-                       n = n_offset;
-               } else {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
-                       break;
-               }
-               }
     }
 
     /**
@@ -2651,35 +2651,35 @@ public class ArrayUtils {
             return;
         }
         if (startIndexInclusive < 0) {
-               startIndexInclusive = 0;
+            startIndexInclusive = 0;
         } 
         if (endIndexExclusive >= array.length) {
-               endIndexExclusive = array.length;
+            endIndexExclusive = array.length;
         }        
         int n = endIndexExclusive - startIndexInclusive;
         if (n <= 1) {
-               return;
+            return;
+        }
+        offset %= n;
+        if (offset < 0) {
+            offset += n;
+        }
+        while (n > 1 && offset > 0) {
+            int n_offset = n - offset;
+            
+            if (offset > n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + n - 
n_offset,  n_offset);
+                n = offset;
+                offset -= n_offset;
+            } else if (offset < n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
+                startIndexInclusive += offset;
+                n = n_offset;
+            } else {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
+                break;
+            }
         }
-       offset %= n;
-       if (offset < 0) {
-               offset += n;
-       }
-               while (n > 1 && offset > 0) {
-                       int n_offset = n - offset;
-                       
-               if (offset > n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n - n_offset,  n_offset);
-                       n = offset;
-                       offset -= n_offset;
-               } else if (offset < n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
-                       startIndexInclusive += offset;
-                       n = n_offset;
-               } else {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
-                       break;
-               }
-               }
     }
 
     /**
@@ -2708,35 +2708,35 @@ public class ArrayUtils {
             return;
         }
         if (startIndexInclusive < 0) {
-               startIndexInclusive = 0;
+            startIndexInclusive = 0;
         } 
         if (endIndexExclusive >= array.length) {
-               endIndexExclusive = array.length;
+            endIndexExclusive = array.length;
         }        
         int n = endIndexExclusive - startIndexInclusive;
         if (n <= 1) {
-               return;
+            return;
+        }
+        offset %= n;
+        if (offset < 0) {
+            offset += n;
+        }
+        while (n > 1 && offset > 0) {
+            int n_offset = n - offset;
+            
+            if (offset > n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + n - 
n_offset,  n_offset);
+                n = offset;
+                offset -= n_offset;
+            } else if (offset < n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
+                startIndexInclusive += offset;
+                n = n_offset;
+            } else {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
+                break;
+            }
         }
-       offset %= n;
-       if (offset < 0) {
-               offset += n;
-       }
-               while (n > 1 && offset > 0) {
-                       int n_offset = n - offset;
-                       
-               if (offset > n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n - n_offset,  n_offset);
-                       n = offset;
-                       offset -= n_offset;
-               } else if (offset < n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
-                       startIndexInclusive += offset;
-                       n = n_offset;
-               } else {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
-                       break;
-               }
-               }
     }
 
     /**
@@ -2765,35 +2765,35 @@ public class ArrayUtils {
             return;
         }
         if (startIndexInclusive < 0) {
-               startIndexInclusive = 0;
+            startIndexInclusive = 0;
         } 
         if (endIndexExclusive >= array.length) {
-               endIndexExclusive = array.length;
+            endIndexExclusive = array.length;
         }        
         int n = endIndexExclusive - startIndexInclusive;
         if (n <= 1) {
-               return;
+            return;
+        }
+        offset %= n;
+        if (offset < 0) {
+            offset += n;
+        }
+        while (n > 1 && offset > 0) {
+            int n_offset = n - offset;
+            
+            if (offset > n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + n - 
n_offset,  n_offset);
+                n = offset;
+                offset -= n_offset;
+            } else if (offset < n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
+                startIndexInclusive += offset;
+                n = n_offset;
+            } else {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
+                break;
+            }
         }
-       offset %= n;
-       if (offset < 0) {
-               offset += n;
-       }
-               while (n > 1 && offset > 0) {
-                       int n_offset = n - offset;
-                       
-               if (offset > n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n - n_offset,  n_offset);
-                       n = offset;
-                       offset -= n_offset;
-               } else if (offset < n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
-                       startIndexInclusive += offset;
-                       n = n_offset;
-               } else {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
-                       break;
-               }
-               }
     }
 
     /**
@@ -2823,35 +2823,35 @@ public class ArrayUtils {
             return;
         }
         if (startIndexInclusive < 0) {
-               startIndexInclusive = 0;
+            startIndexInclusive = 0;
         } 
         if (endIndexExclusive >= array.length) {
-               endIndexExclusive = array.length;
+            endIndexExclusive = array.length;
         }        
         int n = endIndexExclusive - startIndexInclusive;
         if (n <= 1) {
-               return;
+            return;
+        }
+        offset %= n;
+        if (offset < 0) {
+            offset += n;
+        }
+        while (n > 1 && offset > 0) {
+            int n_offset = n - offset;
+            
+            if (offset > n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + n - 
n_offset,  n_offset);
+                n = offset;
+                offset -= n_offset;
+            } else if (offset < n_offset) {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
+                startIndexInclusive += offset;
+                n = n_offset;
+            } else {
+                swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
+                break;
+            }
         }
-       offset %= n;
-       if (offset < 0) {
-               offset += n;
-       }
-               while (n > 1 && offset > 0) {
-                       int n_offset = n - offset;
-                       
-               if (offset > n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n - n_offset,  n_offset);
-                       n = offset;
-                       offset -= n_offset;
-               } else if (offset < n_offset) {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset,  offset);
-                       startIndexInclusive += offset;
-                       n = n_offset;
-               } else {
-                       swap(array, startIndexInclusive, startIndexInclusive + 
n_offset, offset);
-                       break;
-               }
-               }
     }
 
     // IndexOf search

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/06506aec/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java 
b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
index 805375a..5633c9d 100644
--- a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
@@ -2123,9 +2123,21 @@ public class ArrayUtilsTest  {
     public void testSwapChar() {
         char[] array = new char[] {1, 2, 3};
         ArrayUtils.swap(array, 0, 2);
-        assertEquals(3, array[0]);
-        assertEquals(2, array[1]);
-        assertEquals(1, array[2]);
+        assertArrayEquals(new char[] {3, 2, 1}, array);
+        
+        array = new char[] {1, 2, 3};
+        ArrayUtils.swap(array, 0, 0);
+        assertArrayEquals(new char[] {1, 2, 3}, array);
+        
+        array = new char[] {1, 2, 3};
+        ArrayUtils.swap(array, 1, 0);
+        assertArrayEquals(new char[] {2, 1, 3}, array);
+    }
+    
+    @Test(expected = ArrayIndexOutOfBoundsException.class)
+    public void testSwapCharOutOfBounds() {
+        char[] array = new char[] {1, 2, 3};
+        ArrayUtils.swap(array, 0, 5);
     }
 
     @Test

Reply via email to