From: David ‘Bombe’ Roden Date: Thu, 14 Oct 2010 13:03:19 +0000 (+0200) Subject: The used UUIDs are an implementation detail. Hide it. X-Git-Tag: 0.1-RC1~383 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=60e05f5839cc3c00610d861a24003781c3040e11 The used UUIDs are an implementation detail. Hide it. --- diff --git a/src/main/java/net/pterodactylus/sone/data/PostShell.java b/src/main/java/net/pterodactylus/sone/data/PostShell.java index 4a4b797..af9598e 100644 --- a/src/main/java/net/pterodactylus/sone/data/PostShell.java +++ b/src/main/java/net/pterodactylus/sone/data/PostShell.java @@ -21,6 +21,10 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.pterodactylus.util.logging.Logging; /** * {@link Shell} around a {@link Post} that has not yet been retrieved from @@ -30,12 +34,15 @@ import java.util.UUID; */ public class PostShell extends Post implements Shell { + /** The logger. */ + private static final Logger logger = Logging.getLogger(PostShell.class); + /** The shell creator. */ public static final ShellCreator creator = new ShellCreator() { @Override public Shell createShell(String id) { - return new PostShell().setId(UUID.fromString(id)); + return new PostShell().setId(id); } }; @@ -82,8 +89,13 @@ public class PostShell extends Post implements Shell { * The ID of the post * @return This post shell (for method chaining) */ - public PostShell setId(UUID id) { - this.id = id; + public PostShell setId(String id) { + try { + this.id = UUID.fromString(id); + } catch (IllegalArgumentException iae1) { + logger.log(Level.WARNING, "Invalid ID: “" + id + "”.", iae1); + this.id = UUID.randomUUID(); + } return this; } diff --git a/src/main/java/net/pterodactylus/sone/data/ReplyShell.java b/src/main/java/net/pterodactylus/sone/data/ReplyShell.java index 6886a9d..355ef67 100644 --- a/src/main/java/net/pterodactylus/sone/data/ReplyShell.java +++ b/src/main/java/net/pterodactylus/sone/data/ReplyShell.java @@ -18,6 +18,10 @@ package net.pterodactylus.sone.data; import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.pterodactylus.util.logging.Logging; /** * A shell around a {@link Reply} for replies that have not yet been retrieved @@ -27,12 +31,15 @@ import java.util.UUID; */ public class ReplyShell extends Reply implements Shell { + /** The logger. */ + private static final Logger logger = Logging.getLogger(ReplyShell.class); + /** The shell creator. */ public static final ShellCreator creator = new ShellCreator() { @Override public Shell createShell(String id) { - return new ReplyShell().setId(UUID.fromString(id)); + return new ReplyShell().setId(id); } }; @@ -101,8 +108,13 @@ public class ReplyShell extends Reply implements Shell { * The ID of this reply * @return This reply shell (for method chaining) */ - public ReplyShell setId(UUID id) { - this.id = id; + public ReplyShell setId(String id) { + try { + this.id = UUID.fromString(id); + } catch (IllegalArgumentException iae1) { + logger.log(Level.WARNING, "Invalid ID: “" + id + "”.", iae1); + this.id = UUID.randomUUID(); + } return this; } diff --git a/src/main/java/net/pterodactylus/sone/data/SoneShell.java b/src/main/java/net/pterodactylus/sone/data/SoneShell.java index cced1e5..8d8690a 100644 --- a/src/main/java/net/pterodactylus/sone/data/SoneShell.java +++ b/src/main/java/net/pterodactylus/sone/data/SoneShell.java @@ -23,7 +23,10 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.pterodactylus.util.logging.Logging; import freenet.keys.FreenetURI; /** @@ -33,12 +36,15 @@ import freenet.keys.FreenetURI; */ public class SoneShell extends Sone implements Shell { + /** The logger. */ + private static final Logger logger = Logging.getLogger(SoneShell.class); + /** The shell creator. */ public static final ShellCreator creator = new ShellCreator() { @Override public Shell createShell(String id) { - return new SoneShell().setId(UUID.fromString(id)); + return new SoneShell().setId(id); } }; @@ -91,8 +97,13 @@ public class SoneShell extends Sone implements Shell { * The ID of the Sone * @return This Sone shell (for method chaining) */ - public SoneShell setId(UUID id) { - this.id = id; + public SoneShell setId(String id) { + try { + this.id = UUID.fromString(id); + } catch (IllegalArgumentException iae1) { + logger.log(Level.WARNING, "Invalid ID: “" + id + "”.", iae1); + this.id = UUID.randomUUID(); + } return this; }