zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r1438351 - in /zookeeper/trunk: CHANGES.txt src/java/main/org/apache/zookeeper/client/ConnectStringParser.java src/java/main/org/apache/zookeeper/common/StringUtils.java src/java/test/org/apache/zookeeper/test/StringUtilTest.java
Date Fri, 25 Jan 2013 06:54:19 GMT
Author: phunt
Date: Fri Jan 25 06:54:19 2013
New Revision: 1438351

URL: http://svn.apache.org/viewvc?rev=1438351&view=rev
Log:
ZOOKEEPER-1619. Allow spaces in URL (Edward Ribeiro via phunt)

Added:
    zookeeper/trunk/src/java/main/org/apache/zookeeper/common/StringUtils.java
    zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StringUtilTest.java
Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ConnectStringParser.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1438351&r1=1438350&r2=1438351&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Fri Jan 25 06:54:19 2013
@@ -471,6 +471,9 @@ IMPROVEMENTS:
 
   ZOOKEEPER-1535. ZK Shell/Cli re-executes last command on exit (Edward Ribeiro via camille)
 
+  ZOOKEEPER-1619. Allow spaces in URL (Edward Ribeiro via phunt)
+
+
 Release 3.4.0 - 
 
 Non-backward compatible changes:

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ConnectStringParser.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ConnectStringParser.java?rev=1438351&r1=1438350&r2=1438351&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ConnectStringParser.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ConnectStringParser.java Fri
Jan 25 06:54:19 2013
@@ -18,10 +18,13 @@
 
 package org.apache.zookeeper.client;
 
+import org.apache.zookeeper.common.PathUtils;
+
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
+import java.util.List;
 
-import org.apache.zookeeper.common.PathUtils;
+import static org.apache.zookeeper.common.StringUtils.split;
 
 /**
  * A parser for ZooKeeper Client connect strings.
@@ -62,7 +65,7 @@ public final class ConnectStringParser {
             this.chrootPath = null;
         }
 
-        String hostsList[] = connectString.split(",");
+        List<String> hostsList = split(connectString,",");
         for (String host : hostsList) {
             int port = DEFAULT_PORT;
             int pidx = host.lastIndexOf(':');
@@ -84,4 +87,4 @@ public final class ConnectStringParser {
     public ArrayList<InetSocketAddress> getServerAddresses() {
         return serverAddresses;
     }
-}
\ No newline at end of file
+}

Added: zookeeper/trunk/src/java/main/org/apache/zookeeper/common/StringUtils.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/common/StringUtils.java?rev=1438351&view=auto
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/common/StringUtils.java (added)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/common/StringUtils.java Fri Jan 25
06:54:19 2013
@@ -0,0 +1,44 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper.common;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Collections;
+
+public class StringUtils {
+
+    private StringUtils() {/** non instantiable and non inheritable **/}
+
+    /**
+     * This method returns an immutable List<String>, but different from String's split()
+     * it trims the results in the input String, and removes any empty string from
+     * the resulting List.
+     *
+     */
+    public static List<String> split(String value, String separator) {
+        String[] splits = value.split(separator);
+        List<String> results = new ArrayList<String>();
+        for (int i = 0; i < splits.length; i++) {
+            splits[i] = splits[i].trim();
+            if (splits[i].length() > 0) {
+               results.add(splits[i]);
+            }
+        }
+        return Collections.unmodifiableList(results);
+    }
+}

Added: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StringUtilTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StringUtilTest.java?rev=1438351&view=auto
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StringUtilTest.java (added)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/StringUtilTest.java Fri Jan 25
06:54:19 2013
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zookeeper.test;
+
+
+import org.apache.zookeeper.common.StringUtils;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+import static junit.framework.Assert.assertEquals;
+
+public class StringUtilTest {
+
+    @Test
+    public void testStrings() {
+
+        String s1 = "   a  ,   b  , ";
+        assertEquals("[a, b]", StringUtils.split(s1, ",").toString());
+
+        String s2 = "";
+        assertEquals(0, StringUtils.split(s2, ",").size());
+
+        String s3 = "1, , 2";
+        assertEquals("[1, 2]", StringUtils.split(s3, ",").toString());
+
+    }
+}



Mime
View raw message