projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Move Sone parsing into its own class.
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
data
/
impl
/
AbstractImageBuilder.java
diff --git
a/src/main/java/net/pterodactylus/sone/data/impl/AbstractImageBuilder.java
b/src/main/java/net/pterodactylus/sone/data/impl/AbstractImageBuilder.java
index
533ba39
..
13bf24b
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/impl/AbstractImageBuilder.java
+++ b/
src/main/java/net/pterodactylus/sone/data/impl/AbstractImageBuilder.java
@@
-16,10
+16,17
@@
*/
package net.pterodactylus.sone.data.impl;
*/
package net.pterodactylus.sone.data.impl;
+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 com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Preconditions.checkState;
+import static java.lang.System.currentTimeMillis;
+import static java.util.UUID.randomUUID;
import net.pterodactylus.sone.database.ImageBuilder;
import net.pterodactylus.sone.database.ImageBuilder;
+import com.google.common.base.Optional;
+
/**
* Abstract {@link ImageBuilder} implementation. It stores the state of the new
* album and performs validation, you only need to implement {@link #build()}.
/**
* Abstract {@link ImageBuilder} implementation. It stores the state of the new
* album and performs validation, you only need to implement {@link #build()}.
@@
-28,21
+35,34
@@
import net.pterodactylus.sone.database.ImageBuilder;
*/
public abstract class AbstractImageBuilder implements ImageBuilder {
*/
public abstract class AbstractImageBuilder implements ImageBuilder {
- /** Whether to create an album with a random ID. */
- protected boolean randomId;
+ protected Optional<String> id = absent();
+ protected Optional<Long> creationTime = absent();
+ protected String key;
+ protected int width;
+ protected int height;
- /** The ID of the album to create. */
- protected String id;
+ @Override
+ public ImageBuilder withId(String id) {
+ this.id = fromNullable(id);
+ return this;
+ }
@Override
@Override
- public ImageBuilder
randomId(
) {
-
randomId = true
;
+ public ImageBuilder
created(long creationTime
) {
+
this.creationTime = of(creationTime)
;
return this;
}
@Override
return this;
}
@Override
- public ImageBuilder withId(String id) {
- this.id = id;
+ public ImageBuilder at(String key) {
+ this.key = key;
+ return this;
+ }
+
+ @Override
+ public ImageBuilder sized(int width, int height) {
+ this.width = width;
+ this.height = height;
return this;
}
return this;
}
@@
-50,6
+70,14
@@
public abstract class AbstractImageBuilder implements ImageBuilder {
// PROTECTED METHODS
//
// PROTECTED METHODS
//
+ protected String getId() {
+ return id.isPresent() ? id.get() : randomUUID().toString();
+ }
+
+ protected long getCreationTime() {
+ return creationTime.isPresent() ? creationTime.get() : currentTimeMillis();
+ }
+
/**
* Validates the state of this image builder.
*
/**
* Validates the state of this image builder.
*
@@
-57,7
+85,7
@@
public abstract class AbstractImageBuilder implements ImageBuilder {
* if the state is not valid for building a new image
*/
protected void validate() throws IllegalStateException {
* if the state is not valid for building a new image
*/
protected void validate() throws IllegalStateException {
- checkState((
randomId && (id == null)) || (!randomId && (id != null)), "exactly one of random ID or custom ID
must be set");
+ checkState((
width > 0) && (height > 0), "width and height
must be set");
}
}
}
}