From: David ‘Bombe’ Roden Date: Sat, 12 Oct 2013 12:42:52 +0000 (+0200) Subject: Simplify album builder. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=fcf912e985e92d17766736551e69fa53a1730c4b;p=Sone.git Simplify album builder. --- diff --git a/src/main/java/net/pterodactylus/sone/data/impl/AbstractAlbumBuilder.java b/src/main/java/net/pterodactylus/sone/data/impl/AbstractAlbumBuilder.java index 312c795..43511ac 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/AbstractAlbumBuilder.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/AbstractAlbumBuilder.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.data.impl; import static com.google.common.base.Preconditions.checkState; +import static java.util.UUID.randomUUID; import net.pterodactylus.sone.database.AlbumBuilder; @@ -30,10 +31,10 @@ import net.pterodactylus.sone.database.AlbumBuilder; public abstract class AbstractAlbumBuilder implements AlbumBuilder { /** Whether to create an album with a random ID. */ - protected boolean randomId; + private boolean randomId; /** The ID of the album to create. */ - protected String id; + private String id; @Override public AlbumBuilder randomId() { @@ -51,6 +52,10 @@ public abstract class AbstractAlbumBuilder implements AlbumBuilder { // PROTECTED METHODS // + protected String getId() { + return randomId ? randomUUID().toString() : id; + } + /** * Validates the state of this post builder. * diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbumBuilder.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbumBuilder.java index f3e771c..15d9e1f 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbumBuilder.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultAlbumBuilder.java @@ -30,7 +30,7 @@ public class DefaultAlbumBuilder extends AbstractAlbumBuilder { @Override public Album build() throws IllegalStateException { validate(); - return randomId ? new DefaultAlbum() : new DefaultAlbum(id); + return new DefaultAlbum(getId()); } }