You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by "rishabhdaim (via GitHub)" <gi...@apache.org> on 2024/09/02 10:54:51 UTC
[PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
rishabhdaim opened a new pull request, #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679
…ator to set/list
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on code in PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679#discussion_r1743866516
##########
oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtilsTest.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+public class CollectionUtilsTest {
+
+ @Test
+ public void iterableToList() {
+ // create an iterable
+ final List<String> data = Arrays.asList("one", "two", "three");
+ final Iterable<String> iterable = new SimpleIterable<>(data);
+
+ Assert.assertEquals(data, CollectionUtils.toList(iterable));
+
+ }
+
+ @Test
+ public void iteratorToList() {
+ // create an iterator
+ final List<String> data = Arrays.asList("one", "two", "three");
+ final Iterable<String> iterable = new SimpleIterable<>(data);
+
+ Assert.assertEquals(data, CollectionUtils.toList(iterable.iterator()));
+ }
+
+ @Test
+ public void iterableToSet() {
+ // create an iterable
+ final Set<String> data = Set.of("one", "two", "three");
+ final Iterable<String> iterable = new SimpleIterable<>(data);
+
+ Assert.assertEquals(data, CollectionUtils.toSet(iterable));
+ }
+
+ @Test
+ public void iteratorToSet() {
+ // create an iterable
+ final Set<String> data = Set.of("one", "two", "three");
+ final Iterable<String> iterable = new SimpleIterable<>(data);
+
+ Assert.assertEquals(data, CollectionUtils.toSet(iterable.iterator()));
+ }
+}
Review Comment:
added in https://github.com/apache/jackrabbit-oak/pull/1679/commits/cf9b2bc93de33e61604d0559fd000c468d46c9f2
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on code in PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679#discussion_r1740877425
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/package-info.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+
+/**
+ * Annotations for internal use in Oak.
+ */
Review Comment:
added in https://github.com/apache/jackrabbit-oak/pull/1679/commits/35928c9399aec11d7aaf8e6fc6cfcce4b43e902f
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "reschke (via GitHub)" <gi...@apache.org>.
reschke commented on code in PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679#discussion_r1740721060
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.IteratorUtils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/**
+ * Utility methods for collections conversions.
+ */
+public class CollectionUtils {
+
+ private CollectionUtils() {
+ // no instances for you
+ }
+
+ /**
+ * Convert an iterable to a list.The retuning list is mutable and supports all optional operations.
Review Comment:
"Convert an iterable to a list. The returning list is mutable and supports all optional operations."
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.IteratorUtils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/**
+ * Utility methods for collections conversions.
+ */
+public class CollectionUtils {
+
+ private CollectionUtils() {
+ // no instances for you
+ }
+
+ /**
+ * Convert an iterable to a list.The retuning list is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterable<T> iterable) {
+ return IterableUtils.toList(iterable);
+ }
+
+ /**
+ * Convert an iterator to a list. The retuning list is mutable and supports all optional operations.
+ * @param iterator the iterator to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterator<T> iterator) {
+ return IteratorUtils.toList(iterator);
+ }
+
+ /**
+ * Convert an iterable to a set. The retuning set is mutable and supports all optional operations.
Review Comment:
(same)
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.IteratorUtils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/**
+ * Utility methods for collections conversions.
+ */
+public class CollectionUtils {
+
+ private CollectionUtils() {
+ // no instances for you
+ }
+
+ /**
+ * Convert an iterable to a list.The retuning list is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterable<T> iterable) {
+ return IterableUtils.toList(iterable);
+ }
+
+ /**
+ * Convert an iterator to a list. The retuning list is mutable and supports all optional operations.
Review Comment:
"returning"
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/package-info.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+
+/**
+ * Annotations for internal use in Oak.
+ */
Review Comment:
don't we need a vesion number here as well?
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.IteratorUtils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/**
+ * Utility methods for collections conversions.
+ */
+public class CollectionUtils {
+
+ private CollectionUtils() {
+ // no instances for you
+ }
+
+ /**
+ * Convert an iterable to a list.The retuning list is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterable<T> iterable) {
+ return IterableUtils.toList(iterable);
+ }
+
+ /**
+ * Convert an iterator to a list. The retuning list is mutable and supports all optional operations.
+ * @param iterator the iterator to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterator<T> iterator) {
+ return IteratorUtils.toList(iterator);
+ }
+
+ /**
+ * Convert an iterable to a set. The retuning set is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the set
+ * @param <T> the type of the elements
+ */
+ public static <T> Set<T> toSet(final Iterable<T> iterable) {
+ return StreamSupport.stream(iterable.spliterator(), false).collect(Collectors.toSet());
+ }
+
+ /**
+ * Convert an iterator to a set. The retuning set is mutable and supports all optional operations.
Review Comment:
(dito)
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on code in PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679#discussion_r1743866844
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/**
+ * Utility methods for collections conversions.
+ */
+public class CollectionUtils {
+
+ private CollectionUtils() {
+ // no instances for you
+ }
+
+ /**
+ * Convert an iterable to a list.The returning list is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterable<T> iterable) {
+ List<T> result = new ArrayList<>();
+ iterable.forEach(result::add);
+ return result;
+ }
+
+ /**
+ * Convert an iterator to a list. The returning list is mutable and supports all optional operations.
+ * @param iterator the iterator to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterator<T> iterator) {
+ List<T> result = new ArrayList<>();
+ iterator.forEachRemaining(result::add);
+ return result;
+ }
+
+ /**
+ * Convert an iterable to a set. The returning set is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the set
+ * @param <T> the type of the elements
+ */
+ public static <T> Set<T> toSet(final Iterable<T> iterable) {
Review Comment:
addressed in https://github.com/apache/jackrabbit-oak/pull/1679/commits/cf9b2bc93de33e61604d0559fd000c468d46c9f2
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "reschke (via GitHub)" <gi...@apache.org>.
reschke commented on PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679#issuecomment-2325880561
We'll also need to add the package to the export list in the POM. Otherwise this won't ber available in OSGi.
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim merged PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "reschke (via GitHub)" <gi...@apache.org>.
reschke commented on code in PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679#discussion_r1743839221
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/**
+ * Utility methods for collections conversions.
+ */
+public class CollectionUtils {
+
+ private CollectionUtils() {
+ // no instances for you
+ }
+
+ /**
+ * Convert an iterable to a list.The returning list is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterable<T> iterable) {
+ List<T> result = new ArrayList<>();
+ iterable.forEach(result::add);
+ return result;
+ }
+
+ /**
+ * Convert an iterator to a list. The returning list is mutable and supports all optional operations.
+ * @param iterator the iterator to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterator<T> iterator) {
+ List<T> result = new ArrayList<>();
+ iterator.forEachRemaining(result::add);
+ return result;
+ }
+
+ /**
+ * Convert an iterable to a set. The returning set is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the set
+ * @param <T> the type of the elements
+ */
+ public static <T> Set<T> toSet(final Iterable<T> iterable) {
Review Comment:
For consistency, could we implement this in an analogous way (forEachRemaining)?
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/**
+ * Utility methods for collections conversions.
+ */
+public class CollectionUtils {
+
+ private CollectionUtils() {
+ // no instances for you
+ }
+
+ /**
+ * Convert an iterable to a list.The returning list is mutable and supports all optional operations.
Review Comment:
```suggestion
* Convert an iterable to a list. The returning list is mutable and supports all optional operations.
```
##########
oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtilsTest.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+public class CollectionUtilsTest {
+
+ @Test
+ public void iterableToList() {
+ // create an iterable
+ final List<String> data = Arrays.asList("one", "two", "three");
+ final Iterable<String> iterable = new SimpleIterable<>(data);
+
+ Assert.assertEquals(data, CollectionUtils.toList(iterable));
+
+ }
+
+ @Test
+ public void iteratorToList() {
+ // create an iterator
+ final List<String> data = Arrays.asList("one", "two", "three");
+ final Iterable<String> iterable = new SimpleIterable<>(data);
+
+ Assert.assertEquals(data, CollectionUtils.toList(iterable.iterator()));
+ }
+
+ @Test
+ public void iterableToSet() {
+ // create an iterable
+ final Set<String> data = Set.of("one", "two", "three");
+ final Iterable<String> iterable = new SimpleIterable<>(data);
+
+ Assert.assertEquals(data, CollectionUtils.toSet(iterable));
+ }
+
+ @Test
+ public void iteratorToSet() {
+ // create an iterable
+ final Set<String> data = Set.of("one", "two", "three");
+ final Iterable<String> iterable = new SimpleIterable<>(data);
+
+ Assert.assertEquals(data, CollectionUtils.toSet(iterable.iterator()));
+ }
+}
Review Comment:
Maybe add null values to tests?
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on code in PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679#discussion_r1740877940
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.IteratorUtils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/**
+ * Utility methods for collections conversions.
+ */
+public class CollectionUtils {
+
+ private CollectionUtils() {
+ // no instances for you
+ }
+
+ /**
+ * Convert an iterable to a list.The retuning list is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterable<T> iterable) {
+ return IterableUtils.toList(iterable);
+ }
+
+ /**
+ * Convert an iterator to a list. The retuning list is mutable and supports all optional operations.
+ * @param iterator the iterator to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterator<T> iterator) {
+ return IteratorUtils.toList(iterator);
+ }
+
+ /**
+ * Convert an iterable to a set. The retuning set is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the set
+ * @param <T> the type of the elements
+ */
+ public static <T> Set<T> toSet(final Iterable<T> iterable) {
+ return StreamSupport.stream(iterable.spliterator(), false).collect(Collectors.toSet());
+ }
+
+ /**
+ * Convert an iterator to a set. The retuning set is mutable and supports all optional operations.
Review Comment:
addressed in https://github.com/apache/jackrabbit-oak/pull/1679/commits/35928c9399aec11d7aaf8e6fc6cfcce4b43e902f
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "reschke (via GitHub)" <gi...@apache.org>.
reschke commented on code in PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679#discussion_r1743363964
##########
oak-commons/pom.xml:
##########
@@ -103,6 +104,11 @@
<artifactId>oak-shaded-guava</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-collections4</artifactId>
+ <version>4.4</version>
Review Comment:
version should be removed, it's in the parent pom
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "reschke (via GitHub)" <gi...@apache.org>.
reschke commented on PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679#issuecomment-2328293987
FWIW: the dependency isn't new.
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "reschke (via GitHub)" <gi...@apache.org>.
reschke commented on code in PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679#discussion_r1743253666
##########
oak-commons/pom.xml:
##########
@@ -53,7 +53,8 @@
org.apache.jackrabbit.oak.commons.json,
org.apache.jackrabbit.oak.commons.log,
org.apache.jackrabbit.oak.commons.sort,
- org.apache.jackrabbit.oak.commons.properties
+ org.apache.jackrabbit.oak.commons.properties,
Review Comment:
keep it sorted :-)
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on code in PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679#discussion_r1743416190
##########
oak-commons/pom.xml:
##########
@@ -103,6 +104,11 @@
<artifactId>oak-shaded-guava</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-collections4</artifactId>
+ <version>4.4</version>
Review Comment:
addressed in https://github.com/apache/jackrabbit-oak/pull/1679/commits/d44677ee9468e3dc173ab4fd56c7a6a7445aba00
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "thomasmueller (via GitHub)" <gi...@apache.org>.
thomasmueller commented on code in PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679#discussion_r1743330516
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.IteratorUtils;
Review Comment:
These dependencies are not needed (see below).
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.IteratorUtils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/**
+ * Utility methods for collections conversions.
+ */
+public class CollectionUtils {
+
+ private CollectionUtils() {
+ // no instances for you
+ }
+
+ /**
+ * Convert an iterable to a list.The returning list is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterable<T> iterable) {
+ return IterableUtils.toList(iterable);
Review Comment:
```suggestion
List<String> result = new ArrayList<String>();
iterable.forEach(result::add);
return result;
```
iterable.forEach(result::add);
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.IteratorUtils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/**
+ * Utility methods for collections conversions.
+ */
+public class CollectionUtils {
+
+ private CollectionUtils() {
+ // no instances for you
+ }
+
+ /**
+ * Convert an iterable to a list.The returning list is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterable<T> iterable) {
+ return IterableUtils.toList(iterable);
+ }
+
+ /**
+ * Convert an iterator to a list. The returning list is mutable and supports all optional operations.
+ * @param iterator the iterator to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterator<T> iterator) {
+ return IteratorUtils.toList(iterator);
Review Comment:
```suggestion
List<String> result = new ArrayList<String>();
iterator.forEachRemaining(result::add);
return result;
```
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11073 : added conversion utility methods to convert iterable/iter… [jackrabbit-oak]
Posted by "rishabhdaim (via GitHub)" <gi...@apache.org>.
rishabhdaim commented on code in PR #1679:
URL: https://github.com/apache/jackrabbit-oak/pull/1679#discussion_r1740877722
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.IteratorUtils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/**
+ * Utility methods for collections conversions.
+ */
+public class CollectionUtils {
+
+ private CollectionUtils() {
+ // no instances for you
+ }
+
+ /**
+ * Convert an iterable to a list.The retuning list is mutable and supports all optional operations.
Review Comment:
addressed in https://github.com/apache/jackrabbit-oak/pull/1679/commits/35928c9399aec11d7aaf8e6fc6cfcce4b43e902f
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.IteratorUtils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/**
+ * Utility methods for collections conversions.
+ */
+public class CollectionUtils {
+
+ private CollectionUtils() {
+ // no instances for you
+ }
+
+ /**
+ * Convert an iterable to a list.The retuning list is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterable<T> iterable) {
+ return IterableUtils.toList(iterable);
+ }
+
+ /**
+ * Convert an iterator to a list. The retuning list is mutable and supports all optional operations.
Review Comment:
addressed in https://github.com/apache/jackrabbit-oak/pull/1679/commits/35928c9399aec11d7aaf8e6fc6cfcce4b43e902f
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.jackrabbit.oak.commons.collections;
+
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.IteratorUtils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/**
+ * Utility methods for collections conversions.
+ */
+public class CollectionUtils {
+
+ private CollectionUtils() {
+ // no instances for you
+ }
+
+ /**
+ * Convert an iterable to a list.The retuning list is mutable and supports all optional operations.
+ * @param iterable the iterable to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterable<T> iterable) {
+ return IterableUtils.toList(iterable);
+ }
+
+ /**
+ * Convert an iterator to a list. The retuning list is mutable and supports all optional operations.
+ * @param iterator the iterator to convert
+ * @return the list
+ * @param <T> the type of the elements
+ */
+ public static <T> List<T> toList(final Iterator<T> iterator) {
+ return IteratorUtils.toList(iterator);
+ }
+
+ /**
+ * Convert an iterable to a set. The retuning set is mutable and supports all optional operations.
Review Comment:
addressed in https://github.com/apache/jackrabbit-oak/pull/1679/commits/35928c9399aec11d7aaf8e6fc6cfcce4b43e902f
--
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org