From fcf912e985e92d17766736551e69fa53a1730c4b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 12 Oct 2013 14:42:52 +0200 Subject: [PATCH] Simplify album builder. --- .../net/pterodactylus/sone/data/impl/AbstractAlbumBuilder.java | 9 +++++++-- .../net/pterodactylus/sone/data/impl/DefaultAlbumBuilder.java | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) 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()); } } -- 2.7.4