Refactor NoteToSelf to singleton class

This commit is contained in:
AsamK 2021-09-28 21:11:53 +02:00
parent 4acab9043c
commit 7c9fd9d0fb
3 changed files with 4 additions and 9 deletions

View file

@ -12,14 +12,9 @@ public abstract class RecipientIdentifier {
public static class NoteToSelf extends RecipientIdentifier { public static class NoteToSelf extends RecipientIdentifier {
@Override public static NoteToSelf INSTANCE = new NoteToSelf();
public boolean equals(final Object obj) {
return obj instanceof NoteToSelf;
}
@Override private NoteToSelf() {
public int hashCode() {
return 5;
} }
} }

View file

@ -276,7 +276,7 @@ public class DbusSignalImpl implements Signal {
) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity { ) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity {
try { try {
final var results = m.sendMessage(new Message(message, attachments), final var results = m.sendMessage(new Message(message, attachments),
Set.of(new RecipientIdentifier.NoteToSelf())); Set.of(RecipientIdentifier.NoteToSelf.INSTANCE));
checkSendMessageResults(results.getTimestamp(), results.getResults()); checkSendMessageResults(results.getTimestamp(), results.getResults());
return results.getTimestamp(); return results.getTimestamp();
} catch (AttachmentInvalidException e) { } catch (AttachmentInvalidException e) {

View file

@ -25,7 +25,7 @@ public class CommandUtil {
) throws UserErrorException { ) throws UserErrorException {
final var recipientIdentifiers = new HashSet<RecipientIdentifier>(); final var recipientIdentifiers = new HashSet<RecipientIdentifier>();
if (isNoteToSelf) { if (isNoteToSelf) {
recipientIdentifiers.add(new RecipientIdentifier.NoteToSelf()); recipientIdentifiers.add(RecipientIdentifier.NoteToSelf.INSTANCE);
} }
if (recipientStrings != null) { if (recipientStrings != null) {
final var localNumber = m.getUsername(); final var localNumber = m.getUsername();