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_r378934453
 
 

 ##########
 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;
 
 Review comment:
   How about using stream in Java 8?
   `return Arrays.stream(a).boxed().collect(Collectors.toList())`
   
   Actually the entire function can be 
   `return array == null ? Collections.emptyList() : 
Arrays.stream(a).boxed().collect(Collectors.toList())`
   
   Collections.emptyList() returns an immutable list however new ArrayList is 
mutable. So I do not know whether you would like to have a mutable or immutable 
list. This needs to be clarified.
   

----------------------------------------------------------------
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