X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSoneImpl.java;h=86fe3d98c12327afe6ca83d1e331dbe70e7d8627;hp=f57bac922cb5d45657568959ea6fdda0d9e61bb2;hb=2b47186b72e30460a6710f95a76e4a99c305909a;hpb=b507727abe8d1262fc9885ed6be0d036e63cd7e2 diff --git a/src/main/java/net/pterodactylus/sone/data/SoneImpl.java b/src/main/java/net/pterodactylus/sone/data/SoneImpl.java index f57bac9..86fe3d9 100644 --- a/src/main/java/net/pterodactylus/sone/data/SoneImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/SoneImpl.java @@ -18,7 +18,9 @@ package net.pterodactylus.sone.data; import static com.google.common.base.Preconditions.checkNotNull; +import static java.lang.String.format; +import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -28,8 +30,9 @@ import java.util.concurrent.CopyOnWriteArraySet; import java.util.logging.Level; import java.util.logging.Logger; -import net.pterodactylus.sone.core.Options; +import net.pterodactylus.sone.data.SoneOptions.DefaultSoneOptions; import net.pterodactylus.sone.freenet.wot.Identity; +import net.pterodactylus.sone.freenet.wot.OwnIdentity; import net.pterodactylus.util.logging.Logging; import freenet.keys.FreenetURI; @@ -99,10 +102,10 @@ public class SoneImpl implements Sone { private final Set likedReplyIds = new CopyOnWriteArraySet(); /** The root album containing all albums. */ - private final Album rootAlbum = new AlbumImpl().setSone(this); + private final Album rootAlbum = new AlbumImpl(this); /** Sone-specific options. */ - private Options options = new Options(); + private SoneOptions options = new DefaultSoneOptions(); /** * Creates a new Sone. @@ -140,24 +143,6 @@ public class SoneImpl implements Sone { } /** - * Sets the identity of this Sone. The {@link Identity#getId() ID} of the - * identity has to match this Sone’s {@link #getId()}. - * - * @param identity - * The identity of this Sone - * @return This Sone (for method chaining) - * @throws IllegalArgumentException - * if the ID of the identity does not match this Sone’s ID - */ - public SoneImpl setIdentity(Identity identity) throws IllegalArgumentException { - if (!identity.getId().equals(id)) { - throw new IllegalArgumentException("Identity’s ID does not match Sone’s ID!"); - } - this.identity = identity; - return this; - } - - /** * Returns the name of this Sone. * * @return The name of this Sone @@ -209,26 +194,14 @@ public class SoneImpl implements Sone { * @return The insert URI of this Sone */ public FreenetURI getInsertUri() { - return (insertUri != null) ? insertUri.setSuggestedEdition(latestEdition) : null; - } - - /** - * Sets the insert URI of this Sone. - * - * @param insertUri - * The insert URI of this Sone - * @return This Sone (for method chaining) - */ - public Sone setInsertUri(FreenetURI insertUri) { - if (this.insertUri == null) { - this.insertUri = insertUri.setKeyType("USK").setDocName("Sone").setMetaString(new String[0]); - return this; + if (!isLocal()) { + return null; } - if (!this.insertUri.equalsKeypair(insertUri)) { - logger.log(Level.WARNING, String.format("Request URI %s tried to overwrite %s!", insertUri, this.insertUri)); - return this; + try { + return new FreenetURI(((OwnIdentity) getIdentity()).getInsertUri()).setDocName("Sone").setMetaString(new String[0]); + } catch (MalformedURLException e) { + throw new IllegalStateException(format("Own identity %s's insert URI is incorrect.", getIdentity()), e); } - return this; } /** @@ -643,7 +616,7 @@ public class SoneImpl implements Sone { * * @return The options of this Sone */ - public Options getOptions() { + public SoneOptions getOptions() { return options; } @@ -654,7 +627,7 @@ public class SoneImpl implements Sone { * The options of this Sone */ /* TODO - remove this method again, maybe add an option provider */ - public void setOptions(Options options) { + public void setOptions(SoneOptions options) { this.options = options; }