From 0dc6cb55e84d506b7016d75656a3bded7c140b43 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 14 Jul 2026 07:51:57 +0200 Subject: [PATCH] =?utf8?q?=E2=99=BB=EF=B8=8F=20Move=20getRequestUri()=20an?= =?utf8?q?d=20compareTo()=20implementation=20to=20default=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/data/Sone.java | 23 +++++++++++++- .../pterodactylus/sone/data/impl/IdOnlySone.java | 12 -------- .../net/pterodactylus/sone/data/impl/SoneImpl.java | 35 ---------------------- 3 files changed, 22 insertions(+), 48 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index 2b0a2eb..dd48b1f 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -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 { * @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 { /* 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); + } + } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.java b/src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.java index ddd96b9..acac79d 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.java @@ -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; } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java index f2f2ea6..1390a40 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java @@ -18,14 +18,11 @@ 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 - // - - /** {@inheritDoc} */ - @Override - public int compareTo(Sone sone) { - return niceNameComparator().compare(this, sone); - } - - // // OBJECT METHODS // -- 2.7.4