Use .isEmpty() for checking lists and strings

This commit is contained in:
AsamK 2023-10-17 20:01:59 +02:00
parent 9ba70c1808
commit d51dd7ae57
17 changed files with 70 additions and 70 deletions

View file

@ -65,7 +65,7 @@ public class DbusCommandHandler {
SignalControl.class);
try {
final var accounts = control.listAccounts();
if (accounts.size() == 0) {
if (accounts.isEmpty()) {
throw new UserErrorException("No local users found, you first need to register or link an account");
} else if (accounts.size() > 1) {
throw new UserErrorException(

View file

@ -244,7 +244,7 @@ public class DbusManagerImpl implements Manager {
public SendGroupMessageResults quitGroup(
final GroupId groupId, final Set<RecipientIdentifier.Single> groupAdmins
) throws GroupNotFoundException, IOException, NotAGroupMemberException, LastGroupAdminException {
if (groupAdmins.size() > 0) {
if (!groupAdmins.isEmpty()) {
throw new UnsupportedOperationException();
}
final var group = getRemoteObject(signal.getGroup(groupId.serialize()), Signal.Group.class);
@ -522,7 +522,7 @@ public class DbusManagerImpl implements Manager {
if (isWeakListener) {
weakHandlers.add(handler);
} else {
if (messageHandlers.size() == 0) {
if (messageHandlers.isEmpty()) {
installMessageHandlers();
}
messageHandlers.add(handler);
@ -535,7 +535,7 @@ public class DbusManagerImpl implements Manager {
synchronized (messageHandlers) {
weakHandlers.remove(handler);
messageHandlers.remove(handler);
if (messageHandlers.size() == 0) {
if (messageHandlers.isEmpty()) {
uninstallMessageHandlers();
}
}
@ -544,7 +544,7 @@ public class DbusManagerImpl implements Manager {
@Override
public boolean isReceiving() {
synchronized (messageHandlers) {
return messageHandlers.size() > 0;
return !messageHandlers.isEmpty();
}
}
@ -622,7 +622,7 @@ public class DbusManagerImpl implements Manager {
return null;
}
final var contactName = signal.getContactName(n);
if (onlyContacts && contactName.length() == 0) {
if (onlyContacts && contactName.isEmpty()) {
return null;
}
if (name.isPresent() && !name.get().equals(contactName)) {
@ -721,7 +721,7 @@ public class DbusManagerImpl implements Manager {
this.notify();
}
synchronized (messageHandlers) {
if (messageHandlers.size() > 0) {
if (!messageHandlers.isEmpty()) {
uninstallMessageHandlers();
}
weakHandlers.clear();
@ -745,7 +745,7 @@ public class DbusManagerImpl implements Manager {
.map(RecipientIdentifier.Single.class::cast)
.map(RecipientIdentifier.Single::getIdentifier)
.toList();
if (singleRecipients.size() > 0) {
if (!singleRecipients.isEmpty()) {
timestamp = recipientsHandler.apply(singleRecipients);
}

View file

@ -131,7 +131,7 @@ public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler
private List<String> getAttachments(MessageEnvelope.Data message) {
var attachments = new ArrayList<String>();
if (message.attachments().size() > 0) {
if (!message.attachments().isEmpty()) {
for (var attachment : message.attachments()) {
if (attachment.file().isPresent()) {
attachments.add(attachment.file().get().getAbsolutePath());
@ -143,7 +143,7 @@ public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler
private HashMap<String, Variant<?>> getMessageExtras(MessageEnvelope.Data message) {
var extras = new HashMap<String, Variant<?>>();
if (message.attachments().size() > 0) {
if (!message.attachments().isEmpty()) {
var attachments = message.attachments()
.stream()
.filter(a -> a.id().isPresent())
@ -151,7 +151,7 @@ public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler
.toList();
extras.put("attachments", new Variant<>(attachments, "aa{sv}"));
}
if (message.mentions().size() > 0) {
if (!message.mentions().isEmpty()) {
var mentions = message.mentions().stream().map(this::getMentionMap).toList();
extras.put("mentions", new Variant<>(mentions, "aa{sv}"));
}