Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK-11458 : added utils class for replacing Guava's Iterables #2055

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

rishabhdaim
Copy link
Contributor

No description provided.

@rishabhdaim rishabhdaim requested a review from reschke February 6, 2025 07:48
Copy link

github-actions bot commented Feb 6, 2025

Commit-Check ✔️

@reschke
Copy link
Contributor

reschke commented Feb 6, 2025

What do we do when a class needs both our IterarbleUtils and those from commons-collections?

(I'd say implement the methods and delegate)

@rishabhdaim
Copy link
Contributor Author

rishabhdaim commented Feb 6, 2025

This is why I created the IterableUtils inside oak-commons module so we can implement the method with the same name and delegate it to Apache commons-collections4.

@reschke
Copy link
Contributor

reschke commented Feb 6, 2025

Maybe I'm mssing something. Aren't we already using commons-collection4's IterableUtils in other places?

@rishabhdaim
Copy link
Contributor Author

rishabhdaim commented Feb 6, 2025

Yes, we are using commons-collection4's IterableUtils in other places. But for this Iterables.concat use case, we hit a roadblock and had to implement our replacement for Iterables<Iterables> [1].

To avoid using different IterableUtils in each class (and polluting it with a complete class name), I have added other methods (to replace Iterables.concat) in oak-commons IterableUtils.

Now, to avoid using both IterableUtils in the same class for other methods, When we hit this case, we will implement the method in oak-common's IterableUtils and replace it.

So, gradually we would be replacing the commons-collection4's IterableUtils with our delegating methods.

[1] https://guava.dev/releases/20.0/api/docs/com/google/common/collect/Iterables.html#concat-java.lang.Iterable-

@rishabhdaim rishabhdaim requested a review from mbaedke February 6, 2025 15:41
@reschke reschke changed the title OAK-11458 : added utils class for repalcing Guava's Iterables OAK-11458 : added utils class for replacing Guava's Iterables Feb 10, 2025
@reschke
Copy link
Contributor

reschke commented Feb 10, 2025

mbaedke
mbaedke previously approved these changes Feb 10, 2025
@mbaedke mbaedke dismissed their stale review February 10, 2025 14:04

Missed valid complaints from Solarcloud.

@rishabhdaim
Copy link
Contributor Author

@mbaedke the sonar complaints regarding Remove this array creation and simply pass the elements. are due to fact that I am creating an array beforehand passing the variables to an method that accepts varargs.

public static <E> Iterable<E> chainedIterable(final Iterable<? extends E> a,
                                                  final Iterable<? extends E> b) {
        return chainedIterable(new Iterable[] {a, b});
    }

is calling

@SafeVarargs
    public static <E> Iterable<E> chainedIterable(final Iterable<? extends E>... iterables) {
        Objects.requireNonNull(iterables);
        return org.apache.commons.collections4.IterableUtils.chainedIterable(iterables);
    }

from same class i.e. IterableUtils in oak-commons.

In case I don't create an array, I would be calling the caller method thus creating an infinite loop.

public static <E> Iterable<E> chainedIterable(final Iterable<? extends E> a,
                                                  final Iterable<? extends E> b) {
        return chainedIterable(a, b);
    }

this is the same pattern used inside commons-collections4.

One possible way to avoid is to call commons-collections4 api's from each method rather than delegating the call to commons-collections4 to a single method.

public static <E> Iterable<E> chainedIterable(final Iterable<? extends E> a,
                                                  final Iterable<? extends E> b) {
        return org.apache.commons.collections4.IterableUtils.chainedIterable(a, b);
    }

@rishabhdaim
Copy link
Contributor Author

rishabhdaim commented Feb 11, 2025

@mbaedke @reschke changes addressed in 16134e5

* @return an {@code Iterable} that provides a single view of all elements in the input {@code Iterable} instances
* @throws NullPointerException if the input {@code Iterable} or any of its elements are null
*/
public static <E> Iterable<E> chainedIterable(final Iterable<? extends Iterable<? extends E>> iterables) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually used anywhere in the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants