X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FImage.java;h=04eb34932b3837e98c2fe6195444c8674a7c2727;hp=d6e7114c338cc57d4d2f27f10fd240528ad0b6f4;hb=c9e306ac8e3ada846e87a0cc256a20fc148f381c;hpb=5e142aaabb86f62c3962a4bf60b8a79f4e822f5b diff --git a/src/main/java/net/pterodactylus/sone/data/Image.java b/src/main/java/net/pterodactylus/sone/data/Image.java index d6e7114..04eb349 100644 --- a/src/main/java/net/pterodactylus/sone/data/Image.java +++ b/src/main/java/net/pterodactylus/sone/data/Image.java @@ -105,7 +105,7 @@ public class Image implements Fingerprintable { * @return This image */ public Image setSone(Sone sone) { - Validation.begin().isNull("Current Image Owner", this.sone).isNotNull("New Image Owner", sone); + Validation.begin().isNotNull("New Image Owner", sone).isEither("Old Image Owner", this.sone, null, sone).check(); this.sone = sone; return this; } @@ -128,7 +128,7 @@ public class Image implements Fingerprintable { * @return This image */ public Image setAlbum(Album album) { - Validation.begin().isNull("Current Album", this.album).isNotNull("New Album", album).check().isEqual("Album Owner and Image Owner", album.getSone(), getSone()).check(); + Validation.begin().isNotNull("New Album", album).check().isEqual("Album Owner and Image Owner", album.getSone(), getSone()).check(); this.album = album; return this; } @@ -151,7 +151,7 @@ public class Image implements Fingerprintable { * @return This image */ public Image setKey(String key) { - Validation.begin().isNull("Current Image Key", this.key).isNotNull("New Image Key", key).check(); + Validation.begin().isNotNull("New Image Key", key).isEither("Old Image Key", this.key, null, key).check(); this.key = key; return this; } @@ -187,7 +187,7 @@ public class Image implements Fingerprintable { * @return This image */ public Image setCreationTime(long creationTime) { - Validation.begin().isEqual("Current Image Creation Time", this.creationTime, 0).isGreater("New Image Creation Time", creationTime, 0).check(); + Validation.begin().isGreater("New Image Creation Time", creationTime, 0).isEither("Old Image Creation Time", this.creationTime, 0L, creationTime).check(); this.creationTime = creationTime; return this; } @@ -210,7 +210,7 @@ public class Image implements Fingerprintable { * @return This image */ public Image setWidth(int width) { - Validation.begin().isEqual("Current Image Width", this.width, 0).isGreater("New Image Width", width, 0).check(); + Validation.begin().isGreater("New Image Width", width, 0).isEither("Old Image Width", this.width, 0, width).check(); this.width = width; return this; } @@ -233,7 +233,7 @@ public class Image implements Fingerprintable { * @return This image */ public Image setHeight(int height) { - Validation.begin().isEqual("Current Image Height", this.height, 0).isGreater("New Image Height", height, 0); + Validation.begin().isGreater("New Image Height", height, 0).isEither("Old Image Height", this.height, 0, height).check(); this.height = height; return this; } @@ -300,4 +300,27 @@ public class Image implements Fingerprintable { return fingerprint.toString(); } + // + // OBJECT METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return id.hashCode(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object object) { + if (!(object instanceof Image)) { + return false; + } + return ((Image) object).id.equals(id); + } + }