-
Notifications
You must be signed in to change notification settings - Fork 231
Replace Java 1.4 era 'for' loops #1100
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
base: next
Are you sure you want to change the base?
Conversation
Use Enhanced 'for' loops
Use Enhanced 'for' loops
# Conflicts: # src/freenet/clients/http/WelcomeToadlet.java # src/freenet/config/StringArrOption.java # src/freenet/support/PrioritizedSerialExecutor.java
Because we have 50+ open pull requests, and every single one of them would be fucked if we did that. |
Bombe
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.
Some of the variable names you introduced could be improved, too, e.g. the s in String s : methodNamesArray could incredibly well be named methodName to make it more clear what the variable does actually contain.
| if (logMINOR) Logger.minor(this, "Updating bookmark for " + furi + " to edition " + edition); | ||
| matched = true; | ||
| BookmarkItem item = items.get(i); | ||
| BookmarkItem item = bookmarkItem; |
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.
No, please don’t do this, use bookmarkItem instead of item in the line below. 🙂
| Integer prev = results.get(result); | ||
| if(prev == null) prev = 0; | ||
| results.put(result, prev+1); | ||
| if (prev == null) prev = Integer.valueOf(0); |
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.
No manual boxing, please.
| if (a[i] > max) max = a[i]; | ||
| } | ||
| int max; | ||
| max = Integer.max(Arrays.stream(a).reduce(Integer::max).orElse(1), 1); |
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 method does not need to be more than a single line. The declaration does not need to be separate, and the variable can be inlined directly.
| PeerNodeStatus peerNodeStatus; | ||
| double peerLocation; | ||
| int histogramIndex; | ||
| int peerCount = peerNodeStatuses.length; |
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.
peerCount is now unused and can be removed.
| for (int peerIndex = 0; peerIndex < peerCount; peerIndex++) { | ||
| peerNodeStatus = peerNodeStatuses[peerIndex]; | ||
| for (PeerNodeStatus nodeStatus : peerNodeStatuses) { | ||
| peerNodeStatus = nodeStatus; |
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.
Don’t introduce these kind of alias variables, please. Either use the name from the old loop in the for statement, or change all the variables in the loop to what you used in the new for statement.
| Object[] sampleObjects = createSampleObjects(size); | ||
| for (int i=0;i<sampleObjects.length;i++) | ||
| methodLRUQueue.push(sampleObjects[i]); | ||
| for (Object sampleObject : sampleObjects) methodLRUQueue.push(sampleObject); |
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.
Multiple lines and braces, please. For the remainder of this file, too.
| private boolean isPresent(Object[] anArray, Object aElementToSearch) { | ||
| for(int i=0; i<anArray.length; i++) | ||
| if (anArray[i].equals(aElementToSearch)) | ||
| for (Object o : anArray) |
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.
Braces, please.
| methodSFS.putSingle(aPairsArray[i][0], aPairsArray[i][1]); | ||
| for (int i = 0; i < aPairsArray.length; i++) //getting values | ||
| retValue &= methodSFS.get(aPairsArray[i][0]).equals(aPairsArray[i][1]); | ||
| for (String[] value : aPairsArray) methodSFS.putSingle(value[0], value[1]); |
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.
Huh, this pull request started quite well in the “multiple lines and braces” area, but it seems to degrade more and more? I will not comment this on every of the remaining files where this occurs but will mention it here once for the remainder of this pull request: when you change code that either lumps up multiple statements in one line, or that uses multiple lines with identation, but without braces, change that code to be multiple lines (one line per statement) and to have braces around each code block.
| } | ||
|
|
||
| @Test | ||
| public void testToMillis_fractionalMillis() { |
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.
And where did this test go?
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.
Automatic merging seems to mess up with this one and the next one.
| try { | ||
| TimeUtil.toMillis("15250284452w3q7h12m55.807s"); | ||
| } catch (NumberFormatException e) { | ||
| assertNotNull(e); |
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.
Uhm, no. a) This doesn’t even perform the check correctly, i.e. if toMillis does not throw, this test is still green. b) assertThrows is the perfect way to verify that a method throws an exception. c) The exception captured in a catch is always non-null, that assertNotNull is useless.
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 was probably written before assertThrows is supported. Many test cases in this test suite have been updated to use assertThrows.
30+ open pull requests are older than 2 years, and every single one of them already needs complete rework to get merged. |
Address code review feedback from PR hyphanet#1100: - Replace single-letter variables with descriptive names: - s -> metaString, headerValue, nodeReference, octet, nodeName - r -> requestStatus - f -> file - a/b -> nodeA/nodeB - Replace generic 'item' with specific 'bookmarkItem' Based on PR hyphanet#1100 by Juiceman and torusrxxx 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Juiceman <juiceman@hyphanet.org> Co-Authored-By: torusrxxx <torusrxxx@users.noreply.github.com>
This is a replacement for a previous pull request. Review suggestions have been addressed.
However, the code style and white-spaces review is so boring. Why didn't we have an automated tool that fixes it once and for all?