Skip to content

Conversation

@SirCotare
Copy link
Contributor

No description provided.

@SirCotare SirCotare self-assigned this Nov 26, 2025
@SirCotare SirCotare changed the title remove obsolete files update sort parameter Nov 26, 2025
@SirCotare SirCotare requested a review from ThoSap November 27, 2025 07:10
Copy link
Contributor

@ThoSap ThoSap left a comment

Choose a reason for hiding this comment

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

Very nice 👍🏼

Comment on lines +262 to +271
new ArrayList<>(
sortFields.stream()
.filter(sortField -> mapping.containsKey(sortField.property()))
.map(sortField -> new Sort.Order(
sortField.direction(),
mapping.get(sortField.property()),
sortField.nullHandling()
))
.toList()
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This adds additional overhead.

The previous code worked and returned a mutable ArrayList directly, but now we produce an immutable one and then copy it into a new mutable ArrayList.

We could simply remove the comment and create a test that modifies the returned sort to validate that it is mutable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Collectors.toList() explicitly says that

[...]
There are no guarantees on the type, mutability,
     * serializability, or thread-safety of the {@code List} returned;
[...]

So this is the only way to make sure that it is mutable.

Copy link
Contributor

@ThoSap ThoSap Nov 27, 2025

Choose a reason for hiding this comment

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

I know about this line.

All the OpenJDK implementations return a mutable ArrayList.
There is no JDK in the wild that returns an immutable list.

This is why .toList() and .collect(Collectors.toUnmodifiableList()) exist.

https://gemini.google.com/share/c6bc01c56a4c

Comment on lines -86 to +271
sortFields.stream()
.filter(sortField -> mapping.containsKey(sortField.property()))
.map(sortField -> new Sort.Order(
sortField.direction(),
mapping.get(sortField.property()),
sortField.nullHandling()
))
// We do not use .toList() here as we potentially want to modify the sort list later in the StoreImpl
.collect(Collectors.toList())
new ArrayList<>(
sortFields.stream()
.filter(sortField -> mapping.containsKey(sortField.property()))
.map(sortField -> new Sort.Order(
sortField.direction(),
mapping.get(sortField.property()),
sortField.nullHandling()
))
.toList()
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I had Hide whitespace on, so the marked code did not include the previous code.

@SirCotare SirCotare merged commit a0cbf63 into main Nov 27, 2025
1 check passed
@SirCotare SirCotare deleted the update-sorting branch November 27, 2025 07:57
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.

3 participants