You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2012/04/29 17:27:16 UTC

svn commit: r1331925 - in /jackrabbit/oak/trunk/oak-commons/src: main/java/org/apache/jackrabbit/oak/commons/ArrayUtils.java main/java/org/apache/jackrabbit/oak/commons/PathUtils.java test/java/org/apache/jackrabbit/oak/commons/ArrayUtilsTest.java

Author: mduerig
Date: Sun Apr 29 15:27:15 2012
New Revision: 1331925

URL: http://svn.apache.org/viewvc?rev=1331925&view=rev
Log:
minor cleanup:
- add missing @Override
- add private constructor to utility classes
- use isEmpty() instead of size() == 0
- use for each loop
- remove unnecessary boxing

Modified:
    jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/ArrayUtils.java
    jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java
    jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/ArrayUtilsTest.java

Modified: jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/ArrayUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/ArrayUtils.java?rev=1331925&r1=1331924&r2=1331925&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/ArrayUtils.java (original)
+++ jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/ArrayUtils.java Sun Apr 29 15:27:15 2012
@@ -29,6 +29,9 @@ public class ArrayUtils {
     public static final long[] EMPTY_LONG_ARRAY = new long[0];
     public static final int[] EMPTY_INTEGER_ARRAY = new int[0];
 
+    private ArrayUtils() {
+    }
+
     /**
      * Replace an element in a clone of the array at the given position.
      *

Modified: jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java?rev=1331925&r1=1331924&r2=1331925&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java (original)
+++ jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java Sun Apr 29 15:27:15 2012
@@ -40,6 +40,9 @@ public class PathUtils {
 
     private static final String[] EMPTY_ARRAY = new String[0];
 
+    private PathUtils() {
+    }
+
     /**
      * Whether the path is the root path ("/").
      *
@@ -69,7 +72,7 @@ public class PathUtils {
     }
 
     private static boolean isAbsolutePath(String path) {
-        return path.length() > 0 && path.charAt(0) == '/';
+        return !path.isEmpty() && path.charAt(0) == '/';
     }
 
     /**
@@ -95,7 +98,7 @@ public class PathUtils {
     public static String getAncestorPath(String path, int nth) {
         assertValid(path);
 
-        if (path.length() == 0 || denotesRootPath(path)
+        if (path.isEmpty() || denotesRootPath(path)
                 || nth <= 0) {
             return path;
         }
@@ -126,7 +129,7 @@ public class PathUtils {
     public static String getName(String path) {
         assertValid(path);
 
-        if (path.length() == 0 || denotesRootPath(path)) {
+        if (path.isEmpty() || denotesRootPath(path)) {
             return "";
         }
         int end = path.length() - 1;
@@ -173,7 +176,7 @@ public class PathUtils {
     public static String[] split(String path) {
         assertValid(path);
 
-        if (path.length() == 0) {
+        if (path.isEmpty()) {
             return EMPTY_ARRAY;
         } else if (isAbsolutePath(path)) {
             if (path.length() == 1) {
@@ -211,6 +214,7 @@ public class PathUtils {
             int pos = PathUtils.isAbsolute(path) ? 1 : 0;
             String next;
 
+            @Override
             public boolean hasNext() {
                 if (next == null) {
                     if (pos >= path.length()) {
@@ -234,6 +238,7 @@ public class PathUtils {
                 }
             }
 
+            @Override
             public String next() {
                 if (hasNext()) {
                     String next = this.next;
@@ -245,12 +250,14 @@ public class PathUtils {
                 }
             }
 
+            @Override
             public void remove() {
                 throw new UnsupportedOperationException("remove");
             }
         };
 
         return new Iterable<String>() {
+            @Override
             public Iterator<String> iterator() {
                 return it;
             }
@@ -271,13 +278,12 @@ public class PathUtils {
         StringBuilder buff = new StringBuilder(parentLen + size * 5);
         buff.append(parentPath);
         boolean needSlash = parentLen > 0 && !denotesRootPath(parentPath);
-        for (int i = 0; i < size; i++) {
-            String s = relativePaths[i];
+        for (String s : relativePaths) {
             assertValid(s);
             if (isAbsolutePath(s)) {
                 throw new IllegalArgumentException("Cannot append absolute path " + s);
             }
-            if (s.length() > 0) {
+            if (!s.isEmpty()) {
                 if (needSlash) {
                     buff.append('/');
                 }
@@ -299,9 +305,9 @@ public class PathUtils {
         assertValid(parentPath);
         assertValid(subPath);
         // special cases
-        if (parentPath.length() == 0) {
+        if (parentPath.isEmpty()) {
             return subPath;
-        } else if (subPath.length() == 0) {
+        } else if (subPath.isEmpty()) {
             return parentPath;
         } else if (isAbsolutePath(subPath)) {
             throw new IllegalArgumentException("Cannot append absolute path " + subPath);
@@ -324,7 +330,7 @@ public class PathUtils {
     public static boolean isAncestor(String ancestor, String path) {
         assertValid(ancestor);
         assertValid(path);
-        if (ancestor.length() == 0 || path.length() == 0) {
+        if (ancestor.isEmpty() || path.isEmpty()) {
             return false;
         }
         if (!denotesRoot(ancestor)) {
@@ -384,7 +390,7 @@ public class PathUtils {
      * @param path the path
      */
     public static void validate(String path) {
-        if (path.length() == 0 || denotesRootPath(path)) {
+        if (path.isEmpty() || denotesRootPath(path)) {
             return;
         } else if (path.charAt(path.length() - 1) == '/') {
             throw new IllegalArgumentException("Path may not end with '/': " + path);

Modified: jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/ArrayUtilsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/ArrayUtilsTest.java?rev=1331925&r1=1331924&r2=1331925&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/ArrayUtilsTest.java (original)
+++ jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/ArrayUtilsTest.java Sun Apr 29 15:27:15 2012
@@ -16,12 +16,11 @@
  */
 package org.apache.jackrabbit.oak.commons;
 
+import org.junit.Test;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 
-import org.apache.jackrabbit.oak.commons.ArrayUtils;
-import org.junit.Test;
-
 /**
  * Tests the ArrayUtils class
  */
@@ -51,8 +50,8 @@ public class ArrayUtilsTest {
 
     @Test
     public void insertObject() {
-        Long[] x = {Long.valueOf(10), Long.valueOf(20)};
-        Long[] y = ArrayUtils.arrayInsert(x, 1, Long.valueOf(15));
+        Long[] x = {10L, 20L};
+        Long[] y = ArrayUtils.arrayInsert(x, 1, 15L);
         assertFalse(x == y);
         assertEquals(3, y.length);
         assertEquals(Long.valueOf(10), y[0]);
@@ -95,7 +94,7 @@ public class ArrayUtilsTest {
 
     @Test
     public void removeObject() {
-        Long[] x = {Long.valueOf(10), Long.valueOf(20)};
+        Long[] x = {10L, 20L};
         Long[] y = ArrayUtils.arrayRemove(x, 1);
         assertFalse(x == y);
         assertEquals(1, y.length);
@@ -117,8 +116,8 @@ public class ArrayUtilsTest {
 
     @Test
     public void replaceObject() {
-        Long[] x = {Long.valueOf(10), Long.valueOf(20)};
-        Long[] y = ArrayUtils.arrayReplace(x, 1, Long.valueOf(11));
+        Long[] x = {10L, 20L};
+        Long[] y = ArrayUtils.arrayReplace(x, 1, 11L);
         assertFalse(x == y);
         assertEquals(2, y.length);
         assertEquals(Long.valueOf(10), y[0]);