♻️ Move getRequestUri() and compareTo() implementation to default methods
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 14 Jul 2026 05:51:57 +0000 (07:51 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 14 Jul 2026 05:51:57 +0000 (07:51 +0200)
src/main/java/net/pterodactylus/sone/data/Sone.java
src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.java
src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java

index 2b0a2eb..dd48b1f 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.pterodactylus.sone.data;
 
+import java.net.MalformedURLException;
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
@@ -28,6 +29,9 @@ import net.pterodactylus.sone.freenet.wot.Identity;
 
 import freenet.keys.FreenetURI;
 
+import static java.lang.String.format;
+import static net.pterodactylus.sone.data.SoneKt.niceNameComparator;
+
 /**
  * A Sone defines everything about a user: her profile, her status updates, her
  * replies, her likes and dislikes, etc.
@@ -81,7 +85,19 @@ public interface Sone extends Identified, Fingerprintable, Comparable<Sone> {
         * @return The request URI of this Sone
         */
        @Nonnull
-       FreenetURI getRequestUri();
+       default FreenetURI getRequestUri() {
+               try {
+                       return new FreenetURI(getIdentity().getRequestUri())
+                                       .setKeyType("USK")
+                                       .setDocName("Sone")
+                                       .setMetaString(new String[0])
+                                       .setSuggestedEdition(getLatestEdition());
+               } catch (MalformedURLException e) {
+                       throw new IllegalStateException(
+                                       format("Identity %s's request URI is incorrect.",
+                                                       getIdentity()), e);
+               }
+       }
 
        /**
         * Returns the latest edition of this Sone.
@@ -397,4 +413,9 @@ public interface Sone extends Identified, Fingerprintable, Comparable<Sone> {
        /* TODO - remove this method again, maybe add an option provider */
        void setOptions(@Nonnull SoneOptions options);
 
+       @Override
+       default int compareTo(@Nonnull Sone sone) {
+               return niceNameComparator().compare(this, sone);
+       }
+
 }
index ddd96b9..acac79d 100644 (file)
@@ -16,8 +16,6 @@ import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.SoneOptions;
 import net.pterodactylus.sone.freenet.wot.Identity;
 
-import freenet.keys.FreenetURI;
-
 import com.google.common.base.Objects;
 
 /**
@@ -48,11 +46,6 @@ public class IdOnlySone implements Sone {
        }
 
        @Override
-       public FreenetURI getRequestUri() {
-               return null;
-       }
-
-       @Override
        public long getLatestEdition() {
                return 0;
        }
@@ -219,11 +212,6 @@ public class IdOnlySone implements Sone {
        }
 
        @Override
-       public int compareTo(Sone o) {
-               return 0;
-       }
-
-       @Override
        public String getFingerprint() {
                return null;
        }
index f2f2ea6..1390a40 100644 (file)
 package net.pterodactylus.sone.data.impl;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static java.lang.String.format;
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static java.util.logging.Logger.getLogger;
 import static net.pterodactylus.sone.data.PostKt.newestPostFirst;
 import static net.pterodactylus.sone.data.ReplyKt.newestReplyFirst;
-import static net.pterodactylus.sone.data.SoneKt.*;
 
-import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -50,8 +47,6 @@ import net.pterodactylus.sone.data.SoneOptions.DefaultSoneOptions;
 import net.pterodactylus.sone.database.Database;
 import net.pterodactylus.sone.freenet.wot.Identity;
 
-import freenet.keys.FreenetURI;
-
 import com.google.common.hash.Hasher;
 import com.google.common.hash.Hashing;
 
@@ -173,26 +168,6 @@ public class SoneImpl implements Sone {
        }
 
        /**
-        * Returns the request URI of this Sone.
-        *
-        * @return The request URI of this Sone
-        */
-       @Nonnull
-       public FreenetURI getRequestUri() {
-               try {
-                       return new FreenetURI(getIdentity().getRequestUri())
-                                       .setKeyType("USK")
-                                       .setDocName("Sone")
-                                       .setMetaString(new String[0])
-                                       .setSuggestedEdition(latestEdition);
-               } catch (MalformedURLException e) {
-                       throw new IllegalStateException(
-                                       format("Identity %s's request URI is incorrect.",
-                                                       getIdentity()), e);
-               }
-       }
-
-       /**
         * Returns the latest edition of this Sone.
         *
         * @return The latest edition of this Sone
@@ -662,16 +637,6 @@ public class SoneImpl implements Sone {
        }
 
        //
-       // INTERFACE Comparable<Sone>
-       //
-
-       /** {@inheritDoc} */
-       @Override
-       public int compareTo(Sone sone) {
-               return niceNameComparator().compare(this, sone);
-       }
-
-       //
        // OBJECT METHODS
        //