Don’t set the request URI anymore, either.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / SoneImpl.java
index 86fe3d9..86c5935 100644 (file)
@@ -59,7 +59,7 @@ public class SoneImpl implements Sone {
        private final boolean local;
 
        /** The identity of this Sone. */
-       private Identity identity;
+       private final Identity identity;
 
        /** The URI under which the Sone is stored in Freenet. */
        private volatile FreenetURI requestUri;
@@ -110,13 +110,14 @@ public class SoneImpl implements Sone {
        /**
         * Creates a new Sone.
         *
-        * @param id
-        *              The ID of the Sone
+        * @param identity
+        *              The identity of the Sone
         * @param local
         *              {@code true} if the Sone is a local Sone, {@code false} otherwise
         */
-       public SoneImpl(String id, boolean local) {
-               this.id = id;
+       public SoneImpl(Identity identity, boolean local) {
+               this.id = identity.getId();
+               this.identity = identity;
                this.local = local;
        }
 
@@ -166,26 +167,17 @@ public class SoneImpl implements Sone {
         * @return The request URI of this Sone
         */
        public FreenetURI getRequestUri() {
-               return (requestUri != null) ? requestUri.setSuggestedEdition(latestEdition) : null;
-       }
-
-       /**
-        * Sets the request URI of this Sone.
-        *
-        * @param requestUri
-        *              The request URI of this Sone
-        * @return This Sone (for method chaining)
-        */
-       public Sone setRequestUri(FreenetURI requestUri) {
-               if (this.requestUri == null) {
-                       this.requestUri = requestUri.setKeyType("USK").setDocName("Sone").setMetaString(new String[0]);
-                       return this;
-               }
-               if (!this.requestUri.equalsKeypair(requestUri)) {
-                       logger.log(Level.WARNING, String.format("Request URI %s tried to overwrite %s!", requestUri, this.requestUri));
-                       return this;
+               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);
                }
-               return this;
        }
 
        /**