X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FImage.java;h=8d5f0230fd616c261bd4593ba77038ac4fd8aaf7;hp=25a36e3e0e5a4afc48b5da42cc7fd59c895ecc1e;hb=cce88f819ae0ef84b5a86c6a826f88ce0208107f;hpb=a0f01f6f7ff05692e7dd6ab786abf28678e8ca6f diff --git a/src/main/java/net/pterodactylus/sone/data/Image.java b/src/main/java/net/pterodactylus/sone/data/Image.java index 25a36e3..8d5f023 100644 --- a/src/main/java/net/pterodactylus/sone/data/Image.java +++ b/src/main/java/net/pterodactylus/sone/data/Image.java @@ -17,9 +17,11 @@ package net.pterodactylus.sone.data; -import java.util.UUID; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; -import net.pterodactylus.util.validation.Validation; +import java.util.UUID; /** * Container for image metadata. @@ -70,8 +72,7 @@ public class Image implements Fingerprintable { * The ID of the image */ public Image(String id) { - Validation.begin().isNotNull("Image ID", id).check(); - this.id = id; + this.id = checkNotNull(id, "id must not be null"); } // @@ -105,7 +106,8 @@ public class Image implements Fingerprintable { * @return This image */ public Image setSone(Sone sone) { - Validation.begin().isNotNull("New Image Owner", sone).isEither("Old Image Owner", this.sone, null, sone).check(); + checkNotNull(sone, "sone must not be null"); + checkArgument((this.sone == null) || this.sone.equals(sone), "sone must not already be set to another sone"); this.sone = sone; return this; } @@ -128,7 +130,8 @@ public class Image implements Fingerprintable { * @return This image */ public Image setAlbum(Album album) { - Validation.begin().isNotNull("New Album", album).check().isEqual("Album Owner and Image Owner", album.getSone(), getSone()).check(); + checkNotNull(album, "album must not be null"); + checkNotNull(album.getSone().equals(getSone()), "album must belong to the same Sone as this image"); this.album = album; return this; } @@ -151,7 +154,8 @@ public class Image implements Fingerprintable { * @return This image */ public Image setKey(String key) { - Validation.begin().isNotNull("New Image Key", key).isEither("Old Image Key", this.key, null, key).check(); + checkNotNull(key, "key must not be null"); + checkState((this.key == null) || this.key.equals(key), "key must not be already set to another key"); this.key = key; return this; } @@ -187,7 +191,8 @@ public class Image implements Fingerprintable { * @return This image */ public Image setCreationTime(long creationTime) { - Validation.begin().isGreater("New Image Creation Time", creationTime, 0).isEither("Old Image Creation Time", this.creationTime, 0L, creationTime).check(); + checkArgument(creationTime > 0, "creationTime must be > 0"); + checkState((this.creationTime == 0) || (this.creationTime == creationTime), "creationTime must not already be set"); this.creationTime = creationTime; return this; } @@ -210,7 +215,8 @@ public class Image implements Fingerprintable { * @return This image */ public Image setWidth(int width) { - Validation.begin().isGreater("New Image Width", width, 0).isEither("Old Image Width", this.width, 0, width).check(); + checkArgument(width > 0, "width must be > 0"); + checkState((this.width == 0) || (this.width == width), "width must not already be set to another width"); this.width = width; return this; } @@ -233,7 +239,8 @@ public class Image implements Fingerprintable { * @return This image */ public Image setHeight(int height) { - Validation.begin().isGreater("New Image Height", height, 0).isEither("Old Image Height", this.height, 0, height).check(); + checkArgument(height > 0, "height must be > 0"); + checkState((this.height == 0) || (this.height == height), "height must not already be set to another height"); this.height = height; return this; } @@ -255,8 +262,7 @@ public class Image implements Fingerprintable { * @return This image */ public Image setTitle(String title) { - Validation.begin().isNotNull("Image Title", title).check(); - this.title = title; + this.title = checkNotNull(title, "title must not be null"); return this; } @@ -277,8 +283,7 @@ public class Image implements Fingerprintable { * @return This image */ public Image setDescription(String description) { - Validation.begin().isNotNull("Image Description", description).check(); - this.description = description; + this.description = checkNotNull(description, "description must not be null"); return this; }