You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2022/06/03 16:40:39 UTC

[GitHub] [zookeeper] eolivelli commented on a diff in pull request #1891: Add ip filter for zookeeper to control node can operate zk data

eolivelli commented on code in PR #1891:
URL: https://github.com/apache/zookeeper/pull/1891#discussion_r889138853


##########
zookeeper-server/src/main/java/org/apache/zookeeper/common/StringConvertUtil.java:
##########
@@ -0,0 +1,91 @@
+package org.apache.zookeeper.common;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.
+ */
+public class StringConvertUtil {
+    public static final String EMPTY_STRING = "";
+
+    public static final String COMMA = ",";
+
+    public static List<String> parseList(String str, String splitStr) {
+        List<String> list = new ArrayList<String>();
+        if (StringConvertUtil.isBlank(str) || StringConvertUtil.isBlank(splitStr)) {
+            return list;
+        }
+        return StringConvertUtil.toArrayList(str.split(splitStr));
+
+    }
+
+    public static Map<String, String> parseMap(String str, String splitStr) {
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        if (StringConvertUtil.isBlank(str) || StringConvertUtil.isBlank(splitStr)) {
+            return map;
+        }
+        List<String> list = StringConvertUtil.toArrayList(str.split(splitStr));
+        for (String ip : list) {
+            ip = trimToEmpty(ip);
+            map.put(ip, ip);
+
+        }
+        return map;
+
+    }
+
+    public static boolean isBlank(String str) {
+        if (null == str || trimToEmpty(str).isEmpty()) {
+            return true;
+        }
+        return false;
+    }
+
+    public static String trimToEmpty(String str) {
+
+        if (null == str || str.isEmpty()) {
+            return EMPTY_STRING;
+        }
+        return str.trim();
+    }
+
+    public static ArrayList<String> toArrayList(String[] array) {
+        ArrayList<String> arrayList = new ArrayList<String>();
+        if (null == array || 0 == array.length) {
+            return arrayList;
+        }
+        for (int i = 0; i < array.length; i++) {
+            arrayList.add(array[i]);
+        }
+        return arrayList;
+    }
+
+    public static void startThread(Runnable runnable) {

Review Comment:
   Why do we need this code?



##########
zookeeper-server/src/main/java/org/apache/zookeeper/server/NIOServerCnxn.java:
##########
@@ -478,7 +485,10 @@ public void write(char[] cbuf, int off, int len) throws IOException {
         }
 
     }
-    /** Return if four letter word found and responded to, otw false **/

Review Comment:
   Please revert formatting



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org