Skip to content

Fix TorpedoStore issues - #1

Merged
marki-8 merged 4 commits into
mainfrom
bugFix
Oct 13, 2026
Merged

marki-8 merged 4 commits into
mainfrom
bugFix

Conversation

@marki-8

@marki-8 marki-8 commented Oct 12, 2026

Copy link
Copy Markdown
Owner

3 problems shown by SonarQube fixed

@marki-8 marki-8 self-assigned this Oct 12, 2026
@marki-8
marki-8 requested a review from MkDomain October 13, 2026 11:22

private int torpedoCount = 0;

Random generator = new Random();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's use a threadlocal approach instead, we do not need a separate random instance for every TorpedoStore.

public boolean fire(int numberOfTorpedos){
if(numberOfTorpedos < 1 || numberOfTorpedos > this.torpedoCount){
new IllegalArgumentException("numberOfTorpedos");
throw new IllegalArgumentException("numberOfTorpedos");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice catch!

if (r >= FAILURE_RATE) {
// successful firing
this.torpedoCount =- numberOfTorpedos;
this.torpedoCount -= numberOfTorpedos;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Incredible work!

@github-actions

Copy link
Copy Markdown

BA0dHQxeV0kHAEMLCA4=

@sonarqubecloud

Copy link
Copy Markdown

// simulate random overheating of the launcher bay which prevents firing
Random generator = new Random();
double r = generator.nextDouble();
double r = ThreadLocalRandom.current().nextDouble();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice performance improvement!

@github-actions

Copy link
Copy Markdown

BA0dHQxeV0kHAEMLCA4=

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

BA0dHQxeV0kHAEMLCA4=

@marki-8
marki-8 merged commit 96979a0 into main Oct 13, 2026
4 checks passed
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.

2 participants