Skip to content

Commit

Permalink
Replace Collections with Set.of/Map.of/List.of
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamK committed Dec 30, 2020
1 parent bbdd6a8 commit a52f6a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -167,7 +166,7 @@ public String getGroupName(final byte[] groupId) {
public List<String> getGroupMembers(final byte[] groupId) {
GroupInfo group = m.getGroup(GroupId.unknownVersion(groupId));
if (group == null) {
return Collections.emptyList();
return List.of();
} else {
return group.getMembers()
.stream()
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/org/asamk/signal/manager/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -211,7 +210,7 @@ public class Manager implements Closeable {
private final ProfileHelper profileHelper;
private final GroupHelper groupHelper;

public Manager(
Manager(
SignalAccount account,
PathConfig pathConfig,
SignalServiceConfiguration serviceConfiguration,
Expand Down Expand Up @@ -810,7 +809,7 @@ private Pair<GroupId, List<SendMessageResult>> sendUpdateGroupMessage(
GroupInfoV2 gv2 = groupHelper.createGroupV2(name, members, avatarFile);
if (gv2 == null) {
GroupInfoV1 gv1 = new GroupInfoV1(GroupIdV1.createRandom());
gv1.addMembers(Collections.singleton(account.getSelfAddress()));
gv1.addMembers(List.of(account.getSelfAddress()));
updateGroupV1(gv1, name, members, avatarFile);
messageBuilder = getGroupUpdateMessageBuilder(gv1);
g = gv1;
Expand Down Expand Up @@ -965,7 +964,7 @@ Pair<Long, List<SendMessageResult>> sendUpdateGroupMessage(
SignalServiceDataMessage.Builder messageBuilder = getGroupUpdateMessageBuilder(g);

// 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 {
Expand Down Expand Up @@ -1007,14 +1006,14 @@ Pair<Long, List<SendMessageResult>> sendGroupInfoRequest(
.asGroupMessage(group.build());

// 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(
SignalServiceAddress remoteAddress, long messageId
) throws IOException, UntrustedIdentityException {
SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.DELIVERY,
Collections.singletonList(messageId),
List.of(messageId),
System.currentTimeMillis());

createMessageSender().sendReceipt(remoteAddress,
Expand Down Expand Up @@ -1141,7 +1140,7 @@ public void setExpirationTimer(SignalServiceAddress address, int messageExpirati
private void sendExpirationTimerUpdate(SignalServiceAddress address) throws IOException {
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
.asExpirationUpdate();
sendMessage(messageBuilder, Collections.singleton(address));
sendMessage(messageBuilder, List.of(address));
}

/**
Expand Down Expand Up @@ -1434,7 +1433,7 @@ private Pair<Long, List<SendMessageResult>> sendMessage(
.saveIdentity(resolveSignalServiceAddress(e.getIdentifier()),
e.getIdentityKey(),
TrustLevel.UNTRUSTED);
return new Pair<>(timestamp, Collections.emptyList());
return new Pair<>(timestamp, List.of());
}
} else {
// Send to all individually, so sync messages are sent correctly
Expand Down Expand Up @@ -1477,7 +1476,7 @@ private SendMessageResult sendSelfMessage(SignalServiceDataMessage message) thro
message.getTimestamp(),
message,
message.getExpiresInSeconds(),
Collections.singletonMap(recipient, unidentifiedAccess.isPresent()),
Map.of(recipient, unidentifiedAccess.isPresent()),
false);
SignalServiceSyncMessage syncMessage = SignalServiceSyncMessage.forSentTranscript(transcript);

Expand Down Expand Up @@ -2085,7 +2084,7 @@ private List<HandleAction> handleMessage(
syncGroup.removeMember(account.getSelfAddress());
} else {
// 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();
if (g.getColor().isPresent()) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/asamk/signal/manager/ServiceConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -77,7 +76,7 @@ public static SignalServiceConfiguration createDefaultServiceConfiguration(Strin
.header("User-Agent", userAgent)
.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)},
makeSignalCdnUrlMapFor(new SignalCdnUrl[]{new SignalCdnUrl(CDN_URL, TRUST_STORE)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.UuidUtil;

import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -66,7 +65,7 @@ public GroupInviteLinkUrl getGroupInviteLink() {
@Override
public Set<SignalServiceAddress> getMembers() {
if (this.group == null) {
return Collections.emptySet();
return Set.of();
}
return group.getMembersList()
.stream()
Expand All @@ -77,7 +76,7 @@ public Set<SignalServiceAddress> getMembers() {
@Override
public Set<SignalServiceAddress> getPendingMembers() {
if (this.group == null) {
return Collections.emptySet();
return Set.of();
}
return group.getPendingMembersList()
.stream()
Expand All @@ -88,7 +87,7 @@ public Set<SignalServiceAddress> getPendingMembers() {
@Override
public Set<SignalServiceAddress> getRequestingMembers() {
if (this.group == null) {
return Collections.emptySet();
return Set.of();
}
return group.getRequestingMembersList()
.stream()
Expand Down

0 comments on commit a52f6a6

Please sign in to comment.