Replace Collections with Set.of/Map.of/List.of

This commit is contained in:
AsamK 2020-12-30 11:59:24 +01:00
parent bbdd6a8910
commit a52f6a6657
4 changed files with 14 additions and 18 deletions

View file

@ -16,7 +16,6 @@ import org.whispersystems.signalservice.api.util.InvalidNumberException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -167,7 +166,7 @@ public class DbusSignalImpl implements Signal {
public List<String> getGroupMembers(final byte[] groupId) { public List<String> getGroupMembers(final byte[] groupId) {
GroupInfo group = m.getGroup(GroupId.unknownVersion(groupId)); GroupInfo group = m.getGroup(GroupId.unknownVersion(groupId));
if (group == null) { if (group == null) {
return Collections.emptyList(); return List.of();
} else { } else {
return group.getMembers() return group.getMembers()
.stream() .stream()

View file

@ -164,7 +164,6 @@ import java.security.SignatureException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -211,7 +210,7 @@ public class Manager implements Closeable {
private final ProfileHelper profileHelper; private final ProfileHelper profileHelper;
private final GroupHelper groupHelper; private final GroupHelper groupHelper;
public Manager( Manager(
SignalAccount account, SignalAccount account,
PathConfig pathConfig, PathConfig pathConfig,
SignalServiceConfiguration serviceConfiguration, SignalServiceConfiguration serviceConfiguration,
@ -810,7 +809,7 @@ public class Manager implements Closeable {
GroupInfoV2 gv2 = groupHelper.createGroupV2(name, members, avatarFile); GroupInfoV2 gv2 = groupHelper.createGroupV2(name, members, avatarFile);
if (gv2 == null) { if (gv2 == null) {
GroupInfoV1 gv1 = new GroupInfoV1(GroupIdV1.createRandom()); GroupInfoV1 gv1 = new GroupInfoV1(GroupIdV1.createRandom());
gv1.addMembers(Collections.singleton(account.getSelfAddress())); gv1.addMembers(List.of(account.getSelfAddress()));
updateGroupV1(gv1, name, members, avatarFile); updateGroupV1(gv1, name, members, avatarFile);
messageBuilder = getGroupUpdateMessageBuilder(gv1); messageBuilder = getGroupUpdateMessageBuilder(gv1);
g = gv1; g = gv1;
@ -965,7 +964,7 @@ public class Manager implements Closeable {
SignalServiceDataMessage.Builder messageBuilder = getGroupUpdateMessageBuilder(g); SignalServiceDataMessage.Builder messageBuilder = getGroupUpdateMessageBuilder(g);
// Send group message only to the recipient who requested it // Send group message only to the recipient who requested it
return sendMessage(messageBuilder, Collections.singleton(recipient)); return sendMessage(messageBuilder, List.of(recipient));
} }
private SignalServiceDataMessage.Builder getGroupUpdateMessageBuilder(GroupInfoV1 g) throws AttachmentInvalidException { private SignalServiceDataMessage.Builder getGroupUpdateMessageBuilder(GroupInfoV1 g) throws AttachmentInvalidException {
@ -1007,14 +1006,14 @@ public class Manager implements Closeable {
.asGroupMessage(group.build()); .asGroupMessage(group.build());
// Send group info request message to the recipient who sent us a message with this groupId // Send group info request message to the recipient who sent us a message with this groupId
return sendMessage(messageBuilder, Collections.singleton(recipient)); return sendMessage(messageBuilder, List.of(recipient));
} }
void sendReceipt( void sendReceipt(
SignalServiceAddress remoteAddress, long messageId SignalServiceAddress remoteAddress, long messageId
) throws IOException, UntrustedIdentityException { ) throws IOException, UntrustedIdentityException {
SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.DELIVERY, SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.DELIVERY,
Collections.singletonList(messageId), List.of(messageId),
System.currentTimeMillis()); System.currentTimeMillis());
createMessageSender().sendReceipt(remoteAddress, createMessageSender().sendReceipt(remoteAddress,
@ -1141,7 +1140,7 @@ public class Manager implements Closeable {
private void sendExpirationTimerUpdate(SignalServiceAddress address) throws IOException { private void sendExpirationTimerUpdate(SignalServiceAddress address) throws IOException {
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder() final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
.asExpirationUpdate(); .asExpirationUpdate();
sendMessage(messageBuilder, Collections.singleton(address)); sendMessage(messageBuilder, List.of(address));
} }
/** /**
@ -1434,7 +1433,7 @@ public class Manager implements Closeable {
.saveIdentity(resolveSignalServiceAddress(e.getIdentifier()), .saveIdentity(resolveSignalServiceAddress(e.getIdentifier()),
e.getIdentityKey(), e.getIdentityKey(),
TrustLevel.UNTRUSTED); TrustLevel.UNTRUSTED);
return new Pair<>(timestamp, Collections.emptyList()); return new Pair<>(timestamp, List.of());
} }
} else { } else {
// Send to all individually, so sync messages are sent correctly // Send to all individually, so sync messages are sent correctly
@ -1477,7 +1476,7 @@ public class Manager implements Closeable {
message.getTimestamp(), message.getTimestamp(),
message, message,
message.getExpiresInSeconds(), message.getExpiresInSeconds(),
Collections.singletonMap(recipient, unidentifiedAccess.isPresent()), Map.of(recipient, unidentifiedAccess.isPresent()),
false); false);
SignalServiceSyncMessage syncMessage = SignalServiceSyncMessage.forSentTranscript(transcript); SignalServiceSyncMessage syncMessage = SignalServiceSyncMessage.forSentTranscript(transcript);
@ -2085,7 +2084,7 @@ public class Manager implements Closeable {
syncGroup.removeMember(account.getSelfAddress()); syncGroup.removeMember(account.getSelfAddress());
} else { } else {
// Add ourself to the member set as it's marked as active // Add ourself to the member set as it's marked as active
syncGroup.addMembers(Collections.singleton(account.getSelfAddress())); syncGroup.addMembers(List.of(account.getSelfAddress()));
} }
syncGroup.blocked = g.isBlocked(); syncGroup.blocked = g.isBlocked();
if (g.getColor().isPresent()) { if (g.getColor().isPresent()) {

View file

@ -20,7 +20,6 @@ import java.security.KeyStore;
import java.security.KeyStoreException; import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -77,7 +76,7 @@ public class ServiceConfig {
.header("User-Agent", userAgent) .header("User-Agent", userAgent)
.build()); .build());
final List<Interceptor> interceptors = Collections.singletonList(userAgentInterceptor); final List<Interceptor> interceptors = List.of(userAgentInterceptor);
return new SignalServiceConfiguration(new SignalServiceUrl[]{new SignalServiceUrl(URL, TRUST_STORE)}, return new SignalServiceConfiguration(new SignalServiceUrl[]{new SignalServiceUrl(URL, TRUST_STORE)},
makeSignalCdnUrlMapFor(new SignalCdnUrl[]{new SignalCdnUrl(CDN_URL, TRUST_STORE)}, makeSignalCdnUrlMapFor(new SignalCdnUrl[]{new SignalCdnUrl(CDN_URL, TRUST_STORE)},

View file

@ -8,7 +8,6 @@ import org.signal.zkgroup.groups.GroupMasterKey;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.UuidUtil; import org.whispersystems.signalservice.api.util.UuidUtil;
import java.util.Collections;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -66,7 +65,7 @@ public class GroupInfoV2 extends GroupInfo {
@Override @Override
public Set<SignalServiceAddress> getMembers() { public Set<SignalServiceAddress> getMembers() {
if (this.group == null) { if (this.group == null) {
return Collections.emptySet(); return Set.of();
} }
return group.getMembersList() return group.getMembersList()
.stream() .stream()
@ -77,7 +76,7 @@ public class GroupInfoV2 extends GroupInfo {
@Override @Override
public Set<SignalServiceAddress> getPendingMembers() { public Set<SignalServiceAddress> getPendingMembers() {
if (this.group == null) { if (this.group == null) {
return Collections.emptySet(); return Set.of();
} }
return group.getPendingMembersList() return group.getPendingMembersList()
.stream() .stream()
@ -88,7 +87,7 @@ public class GroupInfoV2 extends GroupInfo {
@Override @Override
public Set<SignalServiceAddress> getRequestingMembers() { public Set<SignalServiceAddress> getRequestingMembers() {
if (this.group == null) { if (this.group == null) {
return Collections.emptySet(); return Set.of();
} }
return group.getRequestingMembersList() return group.getRequestingMembersList()
.stream() .stream()