-
Notifications
You must be signed in to change notification settings - Fork 0
update sort parameter #41
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
Conversation
ThoSap
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice 👍🏼
| new ArrayList<>( | ||
| sortFields.stream() | ||
| .filter(sortField -> mapping.containsKey(sortField.property())) | ||
| .map(sortField -> new Sort.Order( | ||
| sortField.direction(), | ||
| mapping.get(sortField.property()), | ||
| sortField.nullHandling() | ||
| )) | ||
| .toList() | ||
| ) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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() | ||
| ) |
There was a problem hiding this comment.
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.
No description provided.