zzzming commented on a change in pull request #6052: [PIP-54] Acknowledgement 
for batch message local index
URL: https://github.com/apache/pulsar/pull/6052#discussion_r378947149
 
 

 ##########
 File path: 
pulsar-common/src/main/java/org/apache/pulsar/common/util/SafeCollectionUtils.java
 ##########
 @@ -0,0 +1,53 @@
+/**
+ * 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.pulsar.common.util;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Safe collection utils.
+ */
+public class SafeCollectionUtils {
+
+    public static List<Long> longArrayToList(long[] array) {
+        if (array == null || array.length == 0) {
+            return Collections.emptyList();
+        } else {
+            List<Long> result = new ArrayList<>(array.length);
+            for (long l : array) {
+                result.add(l);
+            }
+            return result;
+        }
+    }
+
+    public static long[] longListToArray(List<Long> list) {
+        if (list == null || list.size() == 0) {
+            return new long[0];
+        } else {
+            long[] array = new long[list.size()];
+            for (int i = 0; i < list.size(); i++) {
+                array[i] = list.get(i);
+            }
+            return array;
+        }
 
 Review comment:
   Again consider using stream
   `return list == null ? new long[0] : list.stream().mapToLong(l->l).toArray()`
   
   Probably there is no need to have a file to deal with primitive type array 
and list conversion. Does Apache common lang or Guava have library for that?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to