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

@ -127,7 +127,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
final var groupCallUpdate = message.groupCallUpdate().get();
writer.indentedWriter().println("Era id: {}", groupCallUpdate.eraId());
}
if (message.previews().size() > 0) {
if (!message.previews().isEmpty()) {
writer.println("Previews:");
final var previews = message.previews();
for (var preview : previews) {
@ -135,7 +135,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
printPreview(writer.indentedWriter(), preview);
}
}
if (message.sharedContacts().size() > 0) {
if (!message.sharedContacts().isEmpty()) {
writer.println("Contacts:");
for (var contact : message.sharedContacts()) {
writer.println("- Contact:");
@ -176,19 +176,19 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
final var remoteDelete = message.remoteDeleteId().get();
writer.println("Remote delete message: timestamp = {}", remoteDelete);
}
if (message.mentions().size() > 0) {
if (!message.mentions().isEmpty()) {
writer.println("Mentions:");
for (var mention : message.mentions()) {
printMention(writer, mention);
}
}
if (message.textStyles().size() > 0) {
if (!message.textStyles().isEmpty()) {
writer.println("Text styles:");
for (var textStyle : message.textStyles()) {
printTextStyle(writer, textStyle);
}
}
if (message.attachments().size() > 0) {
if (!message.attachments().isEmpty()) {
writer.println("Attachments:");
for (var attachment : message.attachments()) {
writer.println("- Attachment:");
@ -283,7 +283,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
var hangupMessage = callMessage.hangup().get();
writer.println("Hangup message: {}", hangupMessage.id());
}
if (callMessage.iceUpdate().size() > 0) {
if (!callMessage.iceUpdate().isEmpty()) {
writer.println("Ice update messages:");
var iceUpdateMessages = callMessage.iceUpdate();
for (var iceUpdateMessage : iceUpdateMessages) {
@ -313,7 +313,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (syncMessage.groups().isPresent()) {
writer.println("Received sync groups.");
}
if (syncMessage.read().size() > 0) {
if (!syncMessage.read().isEmpty()) {
writer.println("Received sync read messages list");
for (var rm : syncMessage.read()) {
writer.println("- From: {} Message timestamp: {}",
@ -321,7 +321,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
DateUtils.formatTimestamp(rm.timestamp()));
}
}
if (syncMessage.viewed().size() > 0) {
if (!syncMessage.viewed().isEmpty()) {
writer.println("Received sync viewed messages list");
for (var vm : syncMessage.viewed()) {
writer.println("- From: {} Message timestamp: {}",
@ -335,7 +335,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
String to;
if (sentTranscriptMessage.destination().isPresent()) {
to = formatContact(sentTranscriptMessage.destination().get());
} else if (sentTranscriptMessage.recipients().size() > 0) {
} else if (!sentTranscriptMessage.recipients().isEmpty()) {
to = sentTranscriptMessage.recipients()
.stream()
.map(this::formatContact)
@ -429,13 +429,13 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (quote.text().isPresent()) {
writer.println("Text: {}", quote.text().get());
}
if (quote.mentions() != null && quote.mentions().size() > 0) {
if (quote.mentions() != null && !quote.mentions().isEmpty()) {
writer.println("Mentions:");
for (var mention : quote.mentions()) {
printMention(writer, mention);
}
}
if (quote.attachments().size() > 0) {
if (!quote.attachments().isEmpty()) {
writer.println("Attachments:");
for (var attachment : quote.attachments()) {
writer.println("- Attachment:");
@ -478,7 +478,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
writer.println("Organisation: {}", contact.organization().get());
}
if (contact.phone().size() > 0) {
if (!contact.phone().isEmpty()) {
writer.println("Phone details:");
for (var phone : contact.phone()) {
writer.println("- Phone:");
@ -492,7 +492,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
}
}
if (contact.email().size() > 0) {
if (!contact.email().isEmpty()) {
writer.println("Email details:");
for (var email : contact.email()) {
writer.println("- Email:");
@ -506,7 +506,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
}
}
if (contact.address().size() > 0) {
if (!contact.address().isEmpty()) {
writer.println("Address details:");
for (var address : contact.address()) {
writer.println("- Address:");
@ -615,7 +615,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (attachment.isGif()) {
flags.add("video gif");
}
if (flags.size() > 0) {
if (!flags.isEmpty()) {
writer.println("Flags: {}", String.join(", ", flags));
}
if (attachment.width().isPresent() || attachment.height().isPresent()) {

View file

@ -85,7 +85,7 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
final var groupIdStrings = ns.<String>getList("group-id");
final var groupIds = CommandUtil.getGroupIds(groupIdStrings);
if (groupIds.size() > 0) {
if (!groupIds.isEmpty()) {
groups = groups.stream().filter(g -> groupIds.contains(g.groupId())).toList();
}

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}"));
}

View file

@ -35,7 +35,7 @@ public class ServerSentEventSender {
writer.write(event);
writer.write("\n");
}
if (data.size() == 0) {
if (data.isEmpty()) {
writer.write("data\n");
} else {
for (final var d : data) {

View file

@ -38,27 +38,27 @@ record JsonDataMessage(
final var reaction = dataMessage.reaction().map(JsonReaction::from).orElse(null);
final var quote = dataMessage.quote().isPresent() ? JsonQuote.from(dataMessage.quote().get()) : null;
final var payment = dataMessage.payment().isPresent() ? JsonPayment.from(dataMessage.payment().get()) : null;
final var mentions = dataMessage.mentions().size() > 0 ? dataMessage.mentions()
final var mentions = !dataMessage.mentions().isEmpty() ? dataMessage.mentions()
.stream()
.map(JsonMention::from)
.toList() : null;
final var previews = dataMessage.previews().size() > 0 ? dataMessage.previews()
final var previews = !dataMessage.previews().isEmpty() ? dataMessage.previews()
.stream()
.map(JsonPreview::from)
.toList() : null;
final var remoteDelete = dataMessage.remoteDeleteId().isPresent()
? new JsonRemoteDelete(dataMessage.remoteDeleteId().get())
: null;
final var attachments = dataMessage.attachments().size() > 0 ? dataMessage.attachments()
final var attachments = !dataMessage.attachments().isEmpty() ? dataMessage.attachments()
.stream()
.map(JsonAttachment::from)
.toList() : null;
final var sticker = dataMessage.sticker().isPresent() ? JsonSticker.from(dataMessage.sticker().get()) : null;
final var contacts = dataMessage.sharedContacts().size() > 0 ? dataMessage.sharedContacts()
final var contacts = !dataMessage.sharedContacts().isEmpty() ? dataMessage.sharedContacts()
.stream()
.map(JsonSharedContact::from)
.toList() : null;
final var textStyles = dataMessage.textStyles().size() > 0 ? dataMessage.textStyles()
final var textStyles = !dataMessage.textStyles().isEmpty() ? dataMessage.textStyles()
.stream()
.map(JsonTextStyle::from)
.toList() : null;

View file

@ -26,16 +26,16 @@ public record JsonQuote(
final var authorUuid = address.uuid().map(UUID::toString).orElse(null);
final var text = quote.text().orElse(null);
final var mentions = quote.mentions().size() > 0
final var mentions = !quote.mentions().isEmpty()
? quote.mentions().stream().map(JsonMention::from).toList()
: null;
final var attachments = quote.attachments().size() > 0 ? quote.attachments()
final var attachments = !quote.attachments().isEmpty() ? quote.attachments()
.stream()
.map(JsonQuotedAttachment::from)
.toList() : List.<JsonQuotedAttachment>of();
final var textStyles = quote.textStyles().size() > 0 ? quote.textStyles()
final var textStyles = !quote.textStyles().isEmpty() ? quote.textStyles()
.stream()
.map(JsonTextStyle::from)
.toList() : null;

View file

@ -19,15 +19,15 @@ public record JsonSharedContact(
final var name = JsonContactName.from(contact.name());
final var avatar = contact.avatar().isPresent() ? JsonContactAvatar.from(contact.avatar().get()) : null;
final var phone = contact.phone().size() > 0
final var phone = !contact.phone().isEmpty()
? contact.phone().stream().map(JsonContactPhone::from).toList()
: null;
final var email = contact.email().size() > 0
final var email = !contact.email().isEmpty()
? contact.email().stream().map(JsonContactEmail::from).toList()
: null;
final var address = contact.address().size() > 0 ? contact.address()
final var address = !contact.address().isEmpty() ? contact.address()
.stream()
.map(JsonContactAddress::from)
.toList() : null;

View file

@ -45,7 +45,7 @@ record JsonSyncMessage(
blockedGroupIds = null;
}
final var readMessages = syncMessage.read().size() > 0 ? syncMessage.read()
final var readMessages = !syncMessage.read().isEmpty() ? syncMessage.read()
.stream()
.map(JsonSyncReadMessage::from)
.toList() : null;

View file

@ -127,7 +127,7 @@ public class JsonRpcReader {
Util.closeExecutorService(executor);
}
if (responseList.size() > 0) {
if (!responseList.isEmpty()) {
jsonRpcSender.sendBatchResponses(responseList);
}
}
@ -193,7 +193,7 @@ public class JsonRpcReader {
null), null));
return null;
} else if (jsonNode.isArray()) {
if (jsonNode.size() == 0) {
if (jsonNode.isEmpty()) {
jsonRpcSender.sendResponse(JsonRpcResponse.forError(new JsonRpcResponse.Error(JsonRpcResponse.Error.INVALID_REQUEST,
"invalid request",
null), null));

View file

@ -41,12 +41,12 @@ public class Util {
}
private static String toCamelCaseString(List<String> strings) {
if (strings.size() == 0) {
if (strings.isEmpty()) {
return "";
}
return strings.get(0) + strings.stream()
.skip(1)
.filter(s -> s.length() > 0)
.filter(s -> !s.isEmpty())
.map(s -> Character.toUpperCase(s.charAt(0)) + s.substring(1).toLowerCase(Locale.ROOT))
.collect(Collectors.joining());
}