From: David ‘Bombe’ Roden Date: Tue, 15 Oct 2013 20:08:14 +0000 (+0200) Subject: Remove randomId() method from AlbumBuilder. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=90bad7ffc786e04c608162d3b1ec5258e2ae4833;p=Sone.git Remove randomId() method from AlbumBuilder. --- 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 43511ac..6ff935c 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/AbstractAlbumBuilder.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/AbstractAlbumBuilder.java @@ -17,11 +17,14 @@ package net.pterodactylus.sone.data.impl; -import static com.google.common.base.Preconditions.checkState; +import static com.google.common.base.Optional.absent; +import static com.google.common.base.Optional.fromNullable; import static java.util.UUID.randomUUID; import net.pterodactylus.sone.database.AlbumBuilder; +import com.google.common.base.Optional; + /** * Abstract {@link AlbumBuilder} implementation. It stores the state of the new * album and performs validation, you only need to implement {@link #build()}. @@ -30,21 +33,11 @@ import net.pterodactylus.sone.database.AlbumBuilder; */ public abstract class AbstractAlbumBuilder implements AlbumBuilder { - /** Whether to create an album with a random ID. */ - private boolean randomId; - - /** The ID of the album to create. */ - private String id; - - @Override - public AlbumBuilder randomId() { - randomId = true; - return this; - } + private Optional id = absent(); @Override public AlbumBuilder withId(String id) { - this.id = id; + this.id = fromNullable(id); return this; } @@ -53,7 +46,7 @@ public abstract class AbstractAlbumBuilder implements AlbumBuilder { // protected String getId() { - return randomId ? randomUUID().toString() : id; + return id.isPresent() ? id.get() : randomUUID().toString(); } /** @@ -63,7 +56,6 @@ public abstract class AbstractAlbumBuilder implements AlbumBuilder { * if the state is not valid for building a new post */ protected void validate() throws IllegalStateException { - checkState((randomId && (id == null)) || (!randomId && (id != null)), "exactly one of random ID or custom ID must be set"); } } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java index d0c5582..6f77fb4 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java @@ -128,7 +128,7 @@ public class DefaultSone implements Sone { this.database = database; this.id = id; this.local = local; - rootAlbum = new DefaultAlbumBuilder(database, this, null).randomId().build(); + rootAlbum = new DefaultAlbumBuilder(database, this, null).build(); } // diff --git a/src/main/java/net/pterodactylus/sone/database/AlbumBuilder.java b/src/main/java/net/pterodactylus/sone/database/AlbumBuilder.java index b888828..80b163d 100644 --- a/src/main/java/net/pterodactylus/sone/database/AlbumBuilder.java +++ b/src/main/java/net/pterodactylus/sone/database/AlbumBuilder.java @@ -27,13 +27,6 @@ import net.pterodactylus.sone.data.Album; public interface AlbumBuilder { /** - * Configures this builder to create an album with a random ID. - * - * @return This album builder - */ - AlbumBuilder randomId(); - - /** * Configures this builder to create an album with the given ID. * * @param id diff --git a/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.java b/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.java index 4f268ec..30e1e60 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.java +++ b/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.java @@ -72,7 +72,7 @@ public class CreateAlbumPage extends SoneTemplatePage { Sone currentSone = getCurrentSone(request.getToadletContext()); String parentId = request.getHttpRequest().getPartAsStringFailsafe("parent", 36); AlbumBuilderFactory parent = parentId.equals("") ? currentSone : webInterface.getCore().getAlbum(parentId).get(); - Album album = parent.newAlbumBuilder().randomId().build(); + Album album = parent.newAlbumBuilder().build(); return setTitleAndDescription(request, name, album); }