logger.log(Level.WARNING, "Invalid album image encountered, aborting load!");
return;
}
- album.newImageBuilder().withId(imageId).by(sone).created(creationTime).at(key).sized(width, height).build().modify().setTitle(title).setDescription(description).update();
+ album.newImageBuilder().withId(imageId).created(creationTime).at(key).sized(width, height).build().modify().setTitle(title).setDescription(description).update();
}
/* load avatar. */
checkNotNull(temporaryImage, "temporaryImage must not be null");
checkArgument(sone.isLocal(), "sone must be a local Sone");
checkArgument(sone.equals(album.getSone()), "album must belong to the given Sone");
- Image image = album.newImageBuilder().withId(temporaryImage.getId()).by(sone).createdNow().sized(temporaryImage.getWidth(), temporaryImage.getHeight()).build();
+ Image image = album.newImageBuilder().withId(temporaryImage.getId()).createdNow().sized(temporaryImage.getWidth(), temporaryImage.getHeight()).build();
database.storeImage(image);
imageInserter.insertImage(temporaryImage, image);
return image;
logger.log(Level.WARNING, String.format("Downloaded Sone %s contains image %s with invalid dimensions (%s, %s)!", sone, imageId, imageWidthString, imageHeightString));
return null;
}
- Image image = album.newImageBuilder().withId(imageId).by(sone).at(imageKey).created(creationTime).sized(imageWidth, imageHeight).build();
+ Image image = album.newImageBuilder().withId(imageId).at(imageKey).created(creationTime).sized(imageWidth, imageHeight).build();
image = image.modify().setTitle(imageTitle).setDescription(imageDescription).update();
}
}
import static com.google.common.base.Preconditions.checkState;
import static java.util.UUID.randomUUID;
-import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.database.ImageBuilder;
/**
/** The ID of the album to create. */
protected String id;
- protected Sone sone;
protected long creationTime;
protected boolean createdNow;
protected String key;
}
@Override
- public ImageBuilder by(Sone sone) {
- this.sone = sone;
- return this;
- }
-
- @Override
public ImageBuilder created(long creationTime) {
this.creationTime = creationTime;
return this;
*/
protected void validate() throws IllegalStateException {
checkState((randomId && (id == null)) || (!randomId && (id != null)), "exactly one of random ID or custom ID must be set");
- checkState(sone != null, "sone must not be null");
checkState((createdNow && (creationTime == 0)) || (!createdNow && (creationTime > 0)), "exactly one of created now or creation time must be set");
checkState((width > 0) && (height > 0), "width and height must be set");
}
@Override
public ImageBuilder newImageBuilder() throws IllegalStateException {
- return new DefaultImageBuilder(this) {
+ return new DefaultImageBuilder(sone, this) {
@Override
public Image build() throws IllegalStateException {
Image image = super.build();
package net.pterodactylus.sone.data.impl;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Image;
+import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.database.ImageBuilder;
/**
*/
public class DefaultImageBuilder extends AbstractImageBuilder {
+ protected final Sone sone;
protected final Album album;
- public DefaultImageBuilder(Album album) {
- this.album = album;
+ public DefaultImageBuilder(Sone sone, Album album) {
+ this.sone = checkNotNull(sone, "sone must not be null");
+ this.album = checkNotNull(album, "album must not be null");
}
@Override
package net.pterodactylus.sone.database;
import net.pterodactylus.sone.data.Image;
-import net.pterodactylus.sone.data.Sone;
/**
* Builder for {@link Image} objects.
ImageBuilder randomId();
ImageBuilder withId(String id);
- ImageBuilder by(Sone sone);
ImageBuilder created(long creationTime);
ImageBuilder createdNow();
ImageBuilder at(String key);
private final Sone sone = mock(Sone.class);
private final Album album = mock(Album.class);
- private final ImageBuilder imageBuilder = new DefaultImageBuilder(album);
+ private final ImageBuilder imageBuilder = new DefaultImageBuilder(sone, album);
@Test
public void testImageCreationWithAllExplicitParameters() {
- Image image = imageBuilder.withId(ID).by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
+ Image image = imageBuilder.withId(ID).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
assertThat(image, CoreMatchers.notNullValue());
assertThat(image.getId(), is(ID));
assertThat(image.getSone(), is(sone));
@Test
public void testImageCreationWithRandomId() {
Sone sone = mock(Sone.class);
- Image image = imageBuilder.randomId().by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
+ Image image = imageBuilder.randomId().created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
assertThat(image, CoreMatchers.notNullValue());
assertThat(image.getId(), notNullValue());
assertThat(image.getSone(), is(sone));
@Test
public void testImageCreationWithCurrentTime() {
- Image image = imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(WIDTH, HEIGHT).build();
+ Image image = imageBuilder.withId(ID).createdNow().at(KEY).sized(WIDTH, HEIGHT).build();
assertThat(image, CoreMatchers.notNullValue());
assertThat(image.getId(), is(ID));
assertThat(image.getSone(), is(sone));
@Test(expected = IllegalStateException.class)
public void testThatImageCreationWithoutAnIdFails() {
- imageBuilder.by(sone).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
- }
-
- @Test(expected = IllegalStateException.class)
- public void testThatImageCreationWithoutASoneFails() {
- imageBuilder.withId(ID).created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
+ imageBuilder.created(CREATION_TIME).at(KEY).sized(WIDTH, HEIGHT).build();
}
@Test(expected = IllegalStateException.class)
public void testThatImageCreationWithoutATimeFails() {
- imageBuilder.withId(ID).by(sone).at(KEY).sized(WIDTH, HEIGHT).build();
+ imageBuilder.withId(ID).at(KEY).sized(WIDTH, HEIGHT).build();
}
@Test(expected = IllegalStateException.class)
public void testThatImageCreationWithoutASizeFails() {
- imageBuilder.withId(ID).by(sone).createdNow().at(KEY).build();
+ imageBuilder.withId(ID).createdNow().at(KEY).build();
}
@Test(expected = IllegalStateException.class)
public void testThatImageCreationWithoutInvalidWidthFails() {
- imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(0, 1).build();
+ imageBuilder.withId(ID).createdNow().at(KEY).sized(0, 1).build();
}
@Test(expected = IllegalStateException.class)
public void testThatImageCreationWithoutInvalidHeightFails() {
- imageBuilder.withId(ID).by(sone).createdNow().at(KEY).sized(1, 0).build();
+ imageBuilder.withId(ID).createdNow().at(KEY).sized(1, 0).build();
}
}