Skip to content

Commit d61a58e

Browse files
committed
Fixed sonar issues
1 parent ba39ae1 commit d61a58e

5 files changed

Lines changed: 14 additions & 16 deletions

File tree

application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private boolean wasThreadAlreadyHandled(long threadChannelId) {
8989
Instant now = Instant.now();
9090
// NOTE It is necessary to do the "check if exists, otherwise insert" atomic
9191
Instant createdAt = threadIdToCreatedAtCache.get(threadChannelId, _ -> now);
92-
return createdAt != now;
92+
return !createdAt.equals(now);
9393
}
9494

9595
private void handleHelpThreadCreated(ThreadChannel threadChannel) {

application/src/main/java/org/togetherjava/tjbot/features/projects/ProjectsThreadCreatedListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
5151
private boolean wasThreadAlreadyHandled(long threadChannelId) {
5252
Instant now = Instant.now();
5353
Instant createdAt = threadIdToCreatedAtCache.get(threadChannelId, any -> now);
54-
return createdAt != now;
54+
return !createdAt.equals(now);
5555
}
5656

5757
private boolean isPostMessage(ThreadChannel threadChannel, MessageReceivedEvent event) {

application/src/main/java/org/togetherjava/tjbot/features/roleapplication/RoleApplicationHandler.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import java.time.Duration;
2020
import java.time.Instant;
21-
import java.time.OffsetDateTime;
2221
import java.util.List;
22+
import java.util.Objects;
2323
import java.util.Optional;
2424
import java.util.function.Predicate;
2525
import java.util.regex.Pattern;
@@ -35,7 +35,7 @@ public final class RoleApplicationHandler {
3535
private static final Logger logger = LoggerFactory.getLogger(RoleApplicationHandler.class);
3636

3737
private static final int APPLICATION_SUBMIT_COOLDOWN_MINUTES = 5;
38-
private final Cache<Member, OffsetDateTime> applicationSubmitCooldown;
38+
private final Cache<Member, Instant> applicationSubmitCooldown;
3939
private final Predicate<String> applicationChannelPattern;
4040
private final RoleApplicationSystemConfig roleApplicationSystemConfig;
4141

@@ -125,10 +125,6 @@ private Optional<TextChannel> getApplicationChannel(Guild guild) {
125125
.findFirst();
126126
}
127127

128-
public Cache<Member, OffsetDateTime> getApplicationSubmitCooldown() {
129-
return applicationSubmitCooldown;
130-
}
131-
132128
void submitApplicationFromModalInteraction(ModalInteractionEvent event, List<String> args) {
133129
Guild guild = event.getGuild();
134130

@@ -150,13 +146,13 @@ void submitApplicationFromModalInteraction(ModalInteractionEvent event, List<Str
150146
.queue();
151147
}
152148

153-
applicationSubmitCooldown.put(event.getMember(), OffsetDateTime.now());
149+
applicationSubmitCooldown.put(Objects.requireNonNull(event.getMember()), Instant.now());
154150
}
155151

156152
long getMemberCooldownMinutes(Member member) {
157-
OffsetDateTime timeSentCache = getApplicationSubmitCooldown().getIfPresent(member);
153+
Instant timeSentCache = applicationSubmitCooldown.getIfPresent(member);
158154
if (timeSentCache != null) {
159-
Duration duration = Duration.between(timeSentCache, OffsetDateTime.now());
155+
Duration duration = Duration.between(timeSentCache, Instant.now());
160156
return APPLICATION_SUBMIT_COOLDOWN_MINUTES - duration.toMinutes();
161157
}
162158
return 0L;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.togetherjava.tjbot.features.rss;
22

3-
import java.time.ZonedDateTime;
3+
import java.time.Instant;
44

5-
record FailureState(int count, ZonedDateTime lastFailure) {
5+
record FailureState(int count, Instant lastFailure) {
66
}

application/src/main/java/org/togetherjava/tjbot/features/rss/RSSHandlerRoutine.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
import javax.annotation.Nonnull;
3030

3131
import java.io.IOException;
32+
import java.time.Instant;
3233
import java.time.LocalDateTime;
3334
import java.time.ZoneId;
3435
import java.time.ZonedDateTime;
3536
import java.time.format.DateTimeFormatter;
3637
import java.time.format.DateTimeParseException;
38+
import java.time.temporal.ChronoUnit;
3739
import java.util.HashMap;
3840
import java.util.List;
3941
import java.util.Map;
@@ -434,7 +436,7 @@ private List<Item> fetchRSSItemsFromURL(String rssUrl) {
434436
"Possibly dead RSS feed URL: {} - Failed {} times. Please remove it from config.",
435437
rssUrl, newCount);
436438
}
437-
circuitBreaker.put(rssUrl, new FailureState(newCount, ZonedDateTime.now()));
439+
circuitBreaker.put(rssUrl, new FailureState(newCount, Instant.now()));
438440

439441
long blacklistedHours = calculateWaitHours(newCount);
440442

@@ -476,8 +478,8 @@ private boolean isBackingOff(String url) {
476478
}
477479

478480
long waitHours = calculateWaitHours(state.count());
479-
ZonedDateTime retryAt = state.lastFailure().plusHours(waitHours);
481+
Instant retryAt = state.lastFailure().plus(waitHours, ChronoUnit.HOURS);
480482

481-
return ZonedDateTime.now().isBefore(retryAt);
483+
return Instant.now().isBefore(retryAt);
482484
}
483485
}

0 commit comments

Comments
 (0)