Replace collect(Collectors.toList()) with toList()

This commit is contained in:
AsamK 2021-12-11 13:10:39 +01:00
parent 06e93b84da
commit 62687d103f
41 changed files with 106 additions and 199 deletions

View file

@ -160,7 +160,7 @@ public class DbusManagerImpl implements Manager {
(long) device.get("Created").getValue(),
(long) device.get("LastSeen").getValue(),
thisDevice.equals(d.getObjectPath()));
}).collect(Collectors.toList());
}).toList();
}
@Override
@ -191,7 +191,7 @@ public class DbusManagerImpl implements Manager {
@Override
public List<Group> getGroups() {
final var groups = signal.listGroups();
return groups.stream().map(Signal.StructGroup::getObjectPath).map(this::getGroup).collect(Collectors.toList());
return groups.stream().map(Signal.StructGroup::getObjectPath).map(this::getGroup).toList();
}
@Override
@ -216,7 +216,7 @@ public class DbusManagerImpl implements Manager {
final String name, final Set<RecipientIdentifier.Single> members, final File avatarFile
) throws IOException, AttachmentInvalidException {
final var newGroupId = signal.createGroup(emptyIfNull(name),
members.stream().map(RecipientIdentifier.Single::getIdentifier).collect(Collectors.toList()),
members.stream().map(RecipientIdentifier.Single::getIdentifier).toList(),
avatarFile == null ? "" : avatarFile.getPath());
return new Pair<>(GroupId.unknownVersion(newGroupId), new SendGroupMessageResults(0, List.of()));
}
@ -254,28 +254,22 @@ public class DbusManagerImpl implements Manager {
: GroupPermission.EVERY_MEMBER.name());
}
if (updateGroup.getMembers() != null) {
group.addMembers(updateGroup.getMembers()
.stream()
.map(RecipientIdentifier.Single::getIdentifier)
.collect(Collectors.toList()));
group.addMembers(updateGroup.getMembers().stream().map(RecipientIdentifier.Single::getIdentifier).toList());
}
if (updateGroup.getRemoveMembers() != null) {
group.removeMembers(updateGroup.getRemoveMembers()
.stream()
.map(RecipientIdentifier.Single::getIdentifier)
.collect(Collectors.toList()));
.toList());
}
if (updateGroup.getAdmins() != null) {
group.addAdmins(updateGroup.getAdmins()
.stream()
.map(RecipientIdentifier.Single::getIdentifier)
.collect(Collectors.toList()));
group.addAdmins(updateGroup.getAdmins().stream().map(RecipientIdentifier.Single::getIdentifier).toList());
}
if (updateGroup.getRemoveAdmins() != null) {
group.removeAdmins(updateGroup.getRemoveAdmins()
.stream()
.map(RecipientIdentifier.Single::getIdentifier)
.collect(Collectors.toList()));
.toList());
}
if (updateGroup.isResetGroupLink()) {
group.resetLink();
@ -375,9 +369,7 @@ public class DbusManagerImpl implements Manager {
@Override
public SendMessageResults sendEndSessionMessage(final Set<RecipientIdentifier.Single> recipients) throws IOException {
signal.sendEndSessionMessage(recipients.stream()
.map(RecipientIdentifier.Single::getIdentifier)
.collect(Collectors.toList()));
signal.sendEndSessionMessage(recipients.stream().map(RecipientIdentifier.Single::getIdentifier).toList());
return new SendMessageResults(0, Map.of());
}
@ -632,7 +624,7 @@ public class DbusManagerImpl implements Manager {
.filter(r -> r instanceof RecipientIdentifier.Single)
.map(RecipientIdentifier.Single.class::cast)
.map(RecipientIdentifier.Single::getIdentifier)
.collect(Collectors.toList());
.toList();
if (singleRecipients.size() > 0) {
timestamp = recipientsHandler.apply(singleRecipients);
}
@ -644,7 +636,7 @@ public class DbusManagerImpl implements Manager {
.filter(r -> r instanceof RecipientIdentifier.Group)
.map(RecipientIdentifier.Group.class::cast)
.map(RecipientIdentifier.Group::groupId)
.collect(Collectors.toList());
.toList();
for (final var groupId : groupRecipients) {
timestamp = groupHandler.apply(groupId.serialize());
}
@ -826,7 +818,7 @@ public class DbusManagerImpl implements Manager {
getValue(a, "isVoiceNote"),
getValue(a, "isGif"),
getValue(a, "isBorderless"));
}).collect(Collectors.toList());
}).toList();
}
@SuppressWarnings("unchecked")

View file

@ -14,7 +14,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler {
@ -126,11 +125,11 @@ public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler
.stream()
.filter(a -> a.id().isPresent())
.map(this::getAttachmentMap)
.collect(Collectors.toList());
.toList();
extras.put("attachments", new Variant<>(attachments, "aa{sv}"));
}
if (message.mentions().size() > 0) {
var mentions = message.mentions().stream().map(this::getMentionMap).collect(Collectors.toList());
var mentions = message.mentions().stream().map(this::getMentionMap).toList();
extras.put("mentions", new Variant<>(mentions, "aa{sv}"));
}
extras.put("expiresInSeconds", new Variant<>(message.expiresInSeconds()));

View file

@ -18,7 +18,6 @@ import java.net.URI;
import java.nio.channels.OverlappingFileLockException;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
public class DbusSignalControlImpl implements org.asamk.SignalControl {
@ -111,9 +110,6 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
@Override
public List<DBusPath> listAccounts() {
return c.getAccountNumbers()
.stream()
.map(u -> new DBusPath(DbusConfig.getObjectPath(u)))
.collect(Collectors.toList());
return c.getAccountNumbers().stream().map(u -> new DBusPath(DbusConfig.getObjectPath(u))).toList();
}
}

View file

@ -191,9 +191,7 @@ public class DbusSignalImpl implements Signal {
@Override
public long sendMessage(final String message, final List<String> attachments, final String recipient) {
var recipients = new ArrayList<String>(1);
recipients.add(recipient);
return sendMessage(message, attachments, recipients);
return sendMessage(message, attachments, List.of(recipient));
}
@Override
@ -219,9 +217,7 @@ public class DbusSignalImpl implements Signal {
public long sendRemoteDeleteMessage(
final long targetSentTimestamp, final String recipient
) {
var recipients = new ArrayList<String>(1);
recipients.add(recipient);
return sendRemoteDeleteMessage(targetSentTimestamp, recipients);
return sendRemoteDeleteMessage(targetSentTimestamp, List.of(recipient));
}
@Override
@ -266,9 +262,7 @@ public class DbusSignalImpl implements Signal {
final long targetSentTimestamp,
final String recipient
) {
var recipients = new ArrayList<String>(1);
recipients.add(recipient);
return sendMessageReaction(emoji, remove, targetAuthor, targetSentTimestamp, recipients);
return sendMessageReaction(emoji, remove, targetAuthor, targetSentTimestamp, List.of(recipient));
}
@Override
@ -301,10 +295,8 @@ public class DbusSignalImpl implements Signal {
final String recipient, final boolean stop
) throws Error.Failure, Error.GroupNotFound, Error.UntrustedIdentity {
try {
var recipients = new ArrayList<String>(1);
recipients.add(recipient);
final var results = m.sendTypingMessage(stop ? TypingAction.STOP : TypingAction.START,
getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream()
getSingleRecipientIdentifiers(List.of(recipient), m.getSelfNumber()).stream()
.map(RecipientIdentifier.class::cast)
.collect(Collectors.toSet()));
checkSendMessageResults(results.timestamp(), results.results());
@ -499,11 +491,7 @@ public class DbusSignalImpl implements Signal {
@Override
public List<byte[]> getGroupIds() {
var groups = m.getGroups();
var ids = new ArrayList<byte[]>(groups.size());
for (var group : groups) {
ids.add(group.groupId().serialize());
}
return ids;
return groups.stream().map(g -> g.groupId().serialize()).toList();
}
@Override
@ -595,9 +583,8 @@ public class DbusSignalImpl implements Signal {
@Override
public List<Boolean> isRegistered(List<String> numbers) {
var results = new ArrayList<Boolean>();
if (numbers.isEmpty()) {
return results;
return List.of();
}
Map<String, Pair<String, UUID>> registered;
@ -610,7 +597,7 @@ public class DbusSignalImpl implements Signal {
return numbers.stream().map(number -> {
var uuid = registered.get(number).second();
return uuid != null;
}).collect(Collectors.toList());
}).toList();
}
@Override
@ -682,7 +669,7 @@ public class DbusSignalImpl implements Signal {
.map(a -> a.number().orElse(null))
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
.toList();
}
@Override
@ -844,7 +831,7 @@ public class DbusSignalImpl implements Signal {
}
private static List<String> getRecipientStrings(final Set<RecipientAddress> members) {
return members.stream().map(RecipientAddress::getLegacyIdentifier).collect(Collectors.toList());
return members.stream().map(RecipientAddress::getLegacyIdentifier).toList();
}
private static Set<RecipientIdentifier.Single> getSingleRecipientIdentifiers(