Skip to content

Commit fb8df54

Browse files
authored
change to getFirst() and getLast() (#1127)
* change to getFirst() and getLast() * run spotlessApply * fix code smell * remove star import * run spotlessApply * change extra get()
1 parent 7bc47d6 commit fb8df54

File tree

21 files changed

+28
-29
lines changed

21 files changed

+28
-29
lines changed

application/src/main/java/org/togetherjava/tjbot/features/bookmarks/BookmarksListRemoveHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ Request withSelectedBookmarksToRemove(Set<Long> selectedBookmarkIdsToRemove) {
314314
}
315315

316316
static Request fromArgs(List<String> args) {
317-
RequestType requestType = RequestType.valueOf(args.get(0));
317+
RequestType requestType = RequestType.valueOf(args.getFirst());
318318
String componentName = args.get(1);
319319
int currentPageIndex = Integer.parseInt(args.get(2));
320320

application/src/main/java/org/togetherjava/tjbot/features/code/CodeMessageHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private Button createButtonForAction(CodeAction action, long originalMessageId)
152152

153153
@Override
154154
public void onButtonClick(ButtonInteractionEvent event, List<String> args) {
155-
long originalMessageId = Long.parseLong(args.get(0));
155+
long originalMessageId = Long.parseLong(args.getFirst());
156156

157157
event.deferEdit().queue();
158158

application/src/main/java/org/togetherjava/tjbot/features/filesharing/FileSharingMessageListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
9898
@Override
9999
public void onButtonClick(ButtonInteractionEvent event, List<String> args) {
100100
Member interactionUser = event.getMember();
101-
String gistAuthorId = args.get(0);
101+
String gistAuthorId = args.getFirst();
102102
boolean hasSoftModPermissions =
103103
interactionUser.getRoles().stream().map(Role::getName).anyMatch(isSoftModRole);
104104

application/src/main/java/org/togetherjava/tjbot/features/github/GitHubReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
120120
List<MessageEmbed> embeds = new ArrayList<>();
121121

122122
while (matcher.find()) {
123-
long defaultRepoId = config.getGitHubRepositories().get(0);
123+
long defaultRepoId = config.getGitHubRepositories().getFirst();
124124

125125
int issueId = Integer.parseInt(matcher.group(ID_GROUP));
126126
findIssue(issueId, defaultRepoId).ifPresent(issue -> embeds.add(generateReply(issue)));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ private static ForumTag requireTag(String tagName, ForumChannel forumChannel) {
337337
.formatted(forumChannel.getName(), forumChannel.getGuild().getName(), tagName));
338338
}
339339

340-
return matchingTags.get(0);
340+
return matchingTags.getFirst();
341341
}
342342

343343
boolean hasTagManageRole(Member member) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.time.temporal.ChronoUnit;
2626
import java.util.Arrays;
2727
import java.util.EnumMap;
28+
import java.util.List;
2829
import java.util.Locale;
2930
import java.util.Map;
3031
import java.util.Objects;
@@ -213,7 +214,7 @@ private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel hel
213214

214215
helpThread.getHistory()
215216
.retrievePast(1)
216-
.map(messages -> messages.get(0))
217+
.map(List::getFirst)
217218
.queue(lastMessage -> manuallyResetChannelActivityCache.put(helpThread.getIdLong(),
218219
lastMessage.getIdLong()));
219220

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
@@ -179,7 +179,7 @@ private boolean isPostAuthor(Member interactionUser, Message message) {
179179
}
180180

181181
String embedAuthor = Objects
182-
.requireNonNull(message.getEmbeds().get(0).getAuthor(),
182+
.requireNonNull(message.getEmbeds().getFirst().getAuthor(),
183183
"embed author for forum post is null")
184184
.getName();
185185

application/src/main/java/org/togetherjava/tjbot/features/jshell/renderer/RendererUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ static GeneralStatus getGeneralStatus(JShellResult result) {
5959
return GeneralStatus.PARTIAL_SUCCESS; // At least one snippet is a success
6060
}
6161

62-
return getGeneralStatus(
63-
result.snippetsResults().get(result.snippetsResults().size() - 1).status());
62+
return getGeneralStatus(result.snippetsResults().getLast().status());
6463
}
6564

6665
static Color getStatusColor(JShellResult result) {

application/src/main/java/org/togetherjava/tjbot/features/mathcommands/TeXCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private boolean isInvalidInlineFormat(String latex) {
164164

165165
@Override
166166
public void onButtonClick(final ButtonInteractionEvent event, final List<String> args) {
167-
if (!args.get(0).equals(Objects.requireNonNull(event.getMember()).getId())) {
167+
if (!args.getFirst().equals(Objects.requireNonNull(event.getMember()).getId())) {
168168
event.reply("You are not the person who executed the command, you cannot do that")
169169
.setEphemeral(true)
170170
.queue();

application/src/main/java/org/togetherjava/tjbot/features/moderation/ReportCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ private static String createUserReply(Result<Message> result) {
223223
private record ReportedMessage(String content, String id, String jumpUrl, String channelID,
224224
Instant timestamp, String authorName, String authorAvatarUrl) {
225225
static ReportedMessage ofArgs(List<String> args) {
226-
String content = args.get(0);
226+
String content = args.getFirst();
227227
String id = args.get(1);
228228
String jumpUrl = args.get(2);
229229
String channelID = args.get(3);

0 commit comments

Comments
 (0)