-
Notifications
You must be signed in to change notification settings - Fork 0
Create InterceptorClock.java #6
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,12 @@ | ||||||||||||||||||||||||
| public class InterceptorClock { | ||||||||||||||||||||||||
| public static double trackTime(int iterations) { | ||||||||||||||||||||||||
| int tenthsOfSeconds = 0; | ||||||||||||||||||||||||
| double timeSeconds = 0.0; | ||||||||||||||||||||||||
| for (int i = 0; i < iterations; i++) { | ||||||||||||||||||||||||
| tenthsOfSeconds++; | ||||||||||||||||||||||||
| timeSeconds += 0.1; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return timeSeconds; | ||||||||||||||||||||||||
|
Comment on lines
+3
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Simplify time calculation and remove unused variable. Apply this diff: @@ public static double trackTime(int iterations) {
- int tenthsOfSeconds = 0;
- double timeSeconds = 0.0;
- for (int i = 0; i < iterations; i++) {
- tenthsOfSeconds++;
- timeSeconds += 0.1;
- }
-
- return timeSeconds;
+ return iterations * 0.1;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
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.
🛠️ Refactor suggestion
Validate
iterationsinput.Ensure
iterationsis non-negative by throwing anIllegalArgumentExceptionif it’s negative to avoid silent failures.Apply this diff:
@@ public static double trackTime(int iterations) { + if (iterations < 0) { + throw new IllegalArgumentException("iterations must be non-negative"); + }📝 Committable suggestion
🤖 Prompt for AI Agents