]> nmode's Git Repositories - signal-cli/commitdiff
Refactor NoteToSelf to singleton class
authorAsamK <asamk@gmx.de>
Tue, 28 Sep 2021 19:11:53 +0000 (21:11 +0200)
committerAsamK <asamk@gmx.de>
Tue, 28 Sep 2021 19:13:02 +0000 (21:13 +0200)
lib/src/main/java/org/asamk/signal/manager/api/RecipientIdentifier.java
src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java
src/main/java/org/asamk/signal/util/CommandUtil.java

index 4a66cbb37173ce2e9dce1db900ff75a6bc9267c3..cb0a08bbc3538fd19a62fe021a6904dc2c2c533a 100644 (file)
@@ -12,14 +12,9 @@ public abstract class RecipientIdentifier {
 
     public static class NoteToSelf extends RecipientIdentifier {
 
 
     public static class NoteToSelf extends RecipientIdentifier {
 
-        @Override
-        public boolean equals(final Object obj) {
-            return obj instanceof NoteToSelf;
-        }
+        public static NoteToSelf INSTANCE = new NoteToSelf();
 
 
-        @Override
-        public int hashCode() {
-            return 5;
+        private NoteToSelf() {
         }
     }
 
         }
     }
 
index 12cf7d4c37c1ae0440fa767b72c4cd51c7f568b5..e975a67153a09b049e937d12dc686c84f95f90bc 100644 (file)
@@ -276,7 +276,7 @@ public class DbusSignalImpl implements Signal {
     ) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity {
         try {
             final var results = m.sendMessage(new Message(message, attachments),
     ) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity {
         try {
             final var results = m.sendMessage(new Message(message, attachments),
-                    Set.of(new RecipientIdentifier.NoteToSelf()));
+                    Set.of(RecipientIdentifier.NoteToSelf.INSTANCE));
             checkSendMessageResults(results.getTimestamp(), results.getResults());
             return results.getTimestamp();
         } catch (AttachmentInvalidException e) {
             checkSendMessageResults(results.getTimestamp(), results.getResults());
             return results.getTimestamp();
         } catch (AttachmentInvalidException e) {
index 8367487617b16820c720bedbbebeacbcdd435165..18b38a2a7c4d51b0db7997dfddeaa13d1f934978 100644 (file)
@@ -25,7 +25,7 @@ public class CommandUtil {
     ) throws UserErrorException {
         final var recipientIdentifiers = new HashSet<RecipientIdentifier>();
         if (isNoteToSelf) {
     ) throws UserErrorException {
         final var recipientIdentifiers = new HashSet<RecipientIdentifier>();
         if (isNoteToSelf) {
-            recipientIdentifiers.add(new RecipientIdentifier.NoteToSelf());
+            recipientIdentifiers.add(RecipientIdentifier.NoteToSelf.INSTANCE);
         }
         if (recipientStrings != null) {
             final var localNumber = m.getUsername();
         }
         if (recipientStrings != null) {
             final var localNumber = m.getUsername();