X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2Fimpl%2FAbstractReplyBuilder.java;h=5c1b97678bb086d54d795cd47af1c823d2392e44;hb=550219212ea7809a6575b9d6bbe81030cb6f8618;hp=25dd1e1836e4ce8209622742823cfb7d25da6e16;hpb=6d8f11098552fcb40a87d3e35690b3ba760fb947;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java b/src/main/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java index 25dd1e1..5c1b976 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java @@ -17,7 +17,15 @@ package net.pterodactylus.sone.data.impl; -import net.pterodactylus.sone.data.ReplyBuilder; +import static com.google.common.base.Optional.absent; +import static com.google.common.base.Optional.fromNullable; +import static com.google.common.base.Optional.of; +import static java.lang.System.currentTimeMillis; +import static java.util.UUID.randomUUID; + +import net.pterodactylus.sone.database.ReplyBuilder; + +import com.google.common.base.Optional; /** * Abstract implementation of a {@link ReplyBuilder}. @@ -28,20 +36,12 @@ import net.pterodactylus.sone.data.ReplyBuilder; */ public class AbstractReplyBuilder> implements ReplyBuilder { - /** Whether to use a random ID for the reply. */ - protected boolean randomId; - - /** The ID of the reply. */ - protected String id; + protected Optional id = absent(); /** The sender of the reply. */ protected String senderId; - /** Whether to use the current time when creating the reply. */ - protected boolean currentTime; - - /** The time of the reply. */ - protected long time; + protected Optional time = absent(); /** The text of the reply. */ protected String text; @@ -51,18 +51,8 @@ public class AbstractReplyBuilder> implements ReplyBui */ @Override @SuppressWarnings("unchecked") - public B randomId() { - this.randomId = true; - return (B) this; - } - - /** - * {@inheritDoc} - */ - @Override - @SuppressWarnings("unchecked") public B withId(String id) { - this.id = id; + this.id = fromNullable(id); return (B) this; } @@ -81,18 +71,8 @@ public class AbstractReplyBuilder> implements ReplyBui */ @Override @SuppressWarnings("unchecked") - public B currentTime() { - this.currentTime = true; - return (B) this; - } - - /** - * {@inheritDoc} - */ - @Override - @SuppressWarnings("unchecked") public B withTime(long time) { - this.time = time; + this.time = of(time); return (B) this; } @@ -106,4 +86,12 @@ public class AbstractReplyBuilder> implements ReplyBui return (B) this; } + protected String getId() { + return id.isPresent() ? id.get() : randomUUID().toString(); + } + + protected long getTime() { + return time.isPresent() ? time.get() : currentTimeMillis(); + } + }