Skip to content

change to getFirst() and getLast() #1127

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

Merged
merged 6 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ Request withSelectedBookmarksToRemove(Set<Long> selectedBookmarkIdsToRemove) {
}

static Request fromArgs(List<String> args) {
RequestType requestType = RequestType.valueOf(args.get(0));
RequestType requestType = RequestType.valueOf(args.getFirst());
String componentName = args.get(1);
int currentPageIndex = Integer.parseInt(args.get(2));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private Button createButtonForAction(CodeAction action, long originalMessageId)

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

event.deferEdit().queue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
@Override
public void onButtonClick(ButtonInteractionEvent event, List<String> args) {
Member interactionUser = event.getMember();
String gistAuthorId = args.get(0);
String gistAuthorId = args.getFirst();
boolean hasSoftModPermissions =
interactionUser.getRoles().stream().map(Role::getName).anyMatch(isSoftModRole);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
List<MessageEmbed> embeds = new ArrayList<>();

while (matcher.find()) {
long defaultRepoId = config.getGitHubRepositories().get(0);
long defaultRepoId = config.getGitHubRepositories().getFirst();

int issueId = Integer.parseInt(matcher.group(ID_GROUP));
findIssue(issueId, defaultRepoId).ifPresent(issue -> embeds.add(generateReply(issue)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private static ForumTag requireTag(String tagName, ForumChannel forumChannel) {
.formatted(forumChannel.getName(), forumChannel.getGuild().getName(), tagName));
}

return matchingTags.get(0);
return matchingTags.getFirst();
}

boolean hasTagManageRole(Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -213,7 +214,7 @@ private void resetActivity(SlashCommandInteractionEvent event, ThreadChannel hel

helpThread.getHistory()
.retrievePast(1)
.map(messages -> messages.get(0))
.map(List::getFirst)
.queue(lastMessage -> manuallyResetChannelActivityCache.put(helpThread.getIdLong(),
lastMessage.getIdLong()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private boolean isPostAuthor(Member interactionUser, Message message) {
}

String embedAuthor = Objects
.requireNonNull(message.getEmbeds().get(0).getAuthor(),
.requireNonNull(message.getEmbeds().getFirst().getAuthor(),
"embed author for forum post is null")
.getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ static GeneralStatus getGeneralStatus(JShellResult result) {
return GeneralStatus.PARTIAL_SUCCESS; // At least one snippet is a success
}

return getGeneralStatus(
result.snippetsResults().get(result.snippetsResults().size() - 1).status());
return getGeneralStatus(result.snippetsResults().getLast().status());
}

static Color getStatusColor(JShellResult result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private boolean isInvalidInlineFormat(String latex) {

@Override
public void onButtonClick(final ButtonInteractionEvent event, final List<String> args) {
if (!args.get(0).equals(Objects.requireNonNull(event.getMember()).getId())) {
if (!args.getFirst().equals(Objects.requireNonNull(event.getMember()).getId())) {
event.reply("You are not the person who executed the command, you cannot do that")
.setEphemeral(true)
.queue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private static String createUserReply(Result<Message> result) {
private record ReportedMessage(String content, String id, String jumpUrl, String channelID,
Instant timestamp, String authorName, String authorAvatarUrl) {
static ReportedMessage ofArgs(List<String> args) {
String content = args.get(0);
String content = args.getFirst();
String id = args.get(1);
String jumpUrl = args.get(2);
String channelID = args.get(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void onMessageContext(MessageContextInteractionEvent event) {
String originalMessageId = event.getTarget().getId();
String originalChannelId = event.getTarget().getChannel().getId();
String authorId = event.getTarget().getAuthor().getId();
String mostCommonTag = tags.get(0);
String mostCommonTag = tags.getFirst();
String chatGptPrompt =
"Summarize the following text into a concise title or heading not more than 4-5 words, remove quotations if any: %s"
.formatted(originalMessage);
Expand Down Expand Up @@ -142,7 +142,7 @@ public void onMessageContext(MessageContextInteractionEvent event) {
public void onModalSubmitted(ModalInteractionEvent event, List<String> args) {
event.deferReply(true).queue();

String authorId = args.get(0);
String authorId = args.getFirst();
String messageId = args.get(1);
String channelId = args.get(2);
ForumChannel helperForum = getHelperForum(event.getJDA());
Expand Down Expand Up @@ -226,13 +226,13 @@ private RestAction<ForumPostData> createForumPost(ModalInteractionEvent event,
String transferQuestionTag = event.getValue(MODAL_TAG).getAsString();

ForumChannel questionsForum = getHelperForum(event.getJDA());
String mostCommonTag = tags.get(0);
String mostCommonTag = tags.getFirst();

String queryTag =
StringDistances.closestMatch(transferQuestionTag, tags).orElse(mostCommonTag);

ForumTag tag = getTagOrDefault(questionsForum.getAvailableTagsByName(queryTag, true),
() -> questionsForum.getAvailableTagsByName(mostCommonTag, true).get(0));
() -> questionsForum.getAvailableTagsByName(mostCommonTag, true).getFirst());

return questionsForum.createForumPost(forumTitle, forumMessage)
.setTags(ForumTagSnowflake.fromId(tag.getId()))
Expand Down Expand Up @@ -279,7 +279,7 @@ private ForumChannel getHelperForum(JDA jda) {

private static ForumTag getTagOrDefault(List<ForumTag> tagsFoundOnForum,
Supplier<ForumTag> defaultTag) {
return tagsFoundOnForum.isEmpty() ? defaultTag.get() : tagsFoundOnForum.get(0);
return tagsFoundOnForum.isEmpty() ? defaultTag.get() : tagsFoundOnForum.getFirst();
}

private MessageEmbed makeEmbedForPost(User originalUser, String originalMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private List<List<ActionRecord>> groupActionsByPages(List<ActionRecord> actions)
groupedActions.add(new ArrayList<>(AuditCommand.MAX_PAGE_LENGTH));
}

groupedActions.get(groupedActions.size() - 1).add(actions.get(i));
groupedActions.getLast().add(actions.get(i));
}

return groupedActions;
Expand Down Expand Up @@ -271,7 +271,7 @@ public void onButtonClick(ButtonInteractionEvent event, List<String> args) {
int currentPage = Integer.parseInt(args.get(3));
int turnPageBy = Integer.parseInt(args.get(4));

long guildId = Long.parseLong(args.get(0));
long guildId = Long.parseLong(args.getFirst());
long targetId = Long.parseLong(args.get(1));
int pageToDisplay = currentPage + turnPageBy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ private static Instant computeClosestNextScheduleDate(Instant instant,
List<Instant> scheduleDates = scheduleHours.stream()
.map(hour -> dateAtTime.apply(offsetDateTime, hour))
.collect(Collectors.toCollection(ArrayList::new));
int rolloverHour =
(scheduleHours.get(scheduleHours.size() - 1) + periodHours) % HOURS_OF_DAY;
int rolloverHour = (scheduleHours.getLast() + periodHours) % HOURS_OF_DAY;
scheduleDates.add(dateAtTime.apply(offsetDateTime.plusDays(1), rolloverHour));

return scheduleDates.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void onModalSubmitted(ModalInteractionEvent event, List<String> args) {
String userMessage = event.getValue(OPTION_MESSAGE).getAsString();
long userId = event.getUser().getIdLong();

long userGuildId = Long.parseLong(args.get(0));
long userGuildId = Long.parseLong(args.getFirst());
boolean wantsToStayAnonymous = Boolean.parseBoolean(args.get(1));

Optional<TextChannel> modMailAuditLog = getModMailChannel(event.getJDA(), userGuildId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private record ComponentIdArguments(ScamBlockerConfig.Mode mode, long guildId, l
long messageId, long authorId, String contentHash) {

static ComponentIdArguments fromList(List<String> args) {
ScamBlockerConfig.Mode mode = ScamBlockerConfig.Mode.valueOf(args.get(0));
ScamBlockerConfig.Mode mode = ScamBlockerConfig.Mode.valueOf(args.getFirst());
long guildId = Long.parseLong(args.get(1));
long channelId = Long.parseLong(args.get(2));
long messageId = Long.parseLong(args.get(3));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event) {

@Override
public void onButtonClick(ButtonInteractionEvent event, List<String> args) {
int pageToShow = Integer.parseInt(args.get(0));
int pageToShow = Integer.parseInt(args.getFirst());

EmojiUnion emoji = event.getButton().getEmoji();
if (PREVIOUS_BUTTON_EMOJI.equals(emoji)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Instant nextAllowedRequestTime(Instant time) {
return Instant.now();
}

return currentUses.get(0).plus(duration);
return currentUses.getFirst().plus(duration);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void userIsNotLimitedIfOtherUserHasTooManyPendingReminders() {

List<String> remindersOfSecondUser = rawReminders.readReminders(secondUser);
assertEquals(1, remindersOfSecondUser.size());
assertEquals("foo", remindersOfSecondUser.get(0));
assertEquals("foo", remindersOfSecondUser.getFirst());
}

@Test
Expand All @@ -133,6 +133,6 @@ void canCreateReminders() {

List<String> pendingReminders = rawReminders.readReminders();
assertEquals(1, pendingReminders.size());
assertEquals("foo", pendingReminders.get(0));
assertEquals("foo", pendingReminders.getFirst());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private static Button requireSingleButton(List<? extends Button> buttons) {
+ " Either only use a single button or explicitly state the clicked button");
}

return buttons.get(0);
return buttons.getFirst();
}

private ButtonInteractionEvent mockButtonClickEvent(Message message, Button clickedButton) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ static String patchMultiLineComment(String content, String indent) {
/*
* Example multi-line comment
*/
String firstLine = lines.get(0);
String firstLine = lines.getFirst();
List<String> otherLines = lines.subList(1, lines.size());

String otherLinesText = otherLines.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void keywordVersusIdentifier() {
@DisplayName("Each token must be recognized by the expected content and not hidden by another token that prefixes it.")
void typesAreNotHidden(TokenType expectedTokenType) {
String text = expectedTokenType.getContentExample();
TokenType actualTokenType = tokenize(text).get(0);
TokenType actualTokenType = tokenize(text).getFirst();

assertEquals(expectedTokenType, actualTokenType, "Tested on: " + text);
}
Expand Down
Loading