-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Bugfix for migration to Stream API for sum() of List<Integer> #455
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
This commit is a patch for an incorrect refactoring of a foreach loop over a List<Integer> to a sum() call on a Stream.
When the loop variable's type is a primative int rather than an Integer, the current implementation did not add a mapToInt() call to obtain a specialized IntStream object first.
Example:
--------
List<Integer> values = ...
int sum = 0;
for(int i : values) {
sum += i;
}
The code above would refactor to:
int sum = values.stream().sum();
The correct refactoring is:
int sum = values.stream().mapToInt(i -> i).sum();
|
Have you submitted a contributor license agreement? If not, please follow the steps described at http://www.jetbrains.com/agreements/cla/ to sign it. |
|
I have signed the agreement. |
|
Received, thank you. |
…h primitive parameter (inspired by PR #455 by FHannes)
|
Thank you for discovering this bug and providing a pull-request. Indeed this case was not covered. Unfortunately the way you fixed this is not correct. First, it breaks primitive arrays iteration. For example: public int sum(int[] array) {
int sum = 0;
for(int x : array) {
sum += x;
}
return sum;
}This case should be converted to public class Main {
public boolean check(Integer x) {
return x % 3 == 0;
}
public boolean check(int x) {
return x % 2 == 0;
}
public int sum(List<Integer> list) {
int sum = 0;
for(int x : list) {
if(check(x))
sum += x;
}
return sum;
}
public static void main(String[] args) {
System.out.println(new Main().sum(Arrays.asList(1,2,3,4,5,6)));
}
}Here |
|
Alright, that's fine, I'm still in the process of learning how everything in the stream migration system operates. Thank you for the detailed overview! |
We weren't using the TextLinkStyles provided by the LinkAnnotation API, and as a result, our links weren't stateful. We were also not properly setting a disabled colour — now we do. Also changed, we force the Markdown text to not be focusable, even if it is clickable, since we don't want it to get focused. Now only links are focused while tabbing through Markdown. This also removes some testing harness left around from #425, and that we don't need anymore. Note: links should have a border around them when they are focused, but that's not possible with the Compose APIs. What we do instead is show a subtle background color, taken from the ActionButtons' hover and pressed states, for our focused and pressed states, respectively. GitOrigin-RevId: 8cd3eee5791dbdb5f4f96f4e569e1f28923d1619
This commit is a patch for an incorrect refactoring of a foreach loop over a List to a sum() call on a Stream.
When the loop variable's type is a primitive int rather than an Integer, the current implementation did not add a mapToInt() call to obtain a specialized IntStream object first.
Example:
The code above would refactor to:
int sum = values.stream().sum();The correct refactoring is:
int sum = values.stream().mapToInt(i -> i).sum();