X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FImage.java;h=25a36e3e0e5a4afc48b5da42cc7fd59c895ecc1e;hp=f38a4facedfde21660f1668374bf615439106f8e;hb=a47643aed43d118ca68044f95451bb5374cdb332;hpb=f02b9927ab88167c7ce5da4b01dc744e6a6404f2 diff --git a/src/main/java/net/pterodactylus/sone/data/Image.java b/src/main/java/net/pterodactylus/sone/data/Image.java index f38a4fa..25a36e3 100644 --- a/src/main/java/net/pterodactylus/sone/data/Image.java +++ b/src/main/java/net/pterodactylus/sone/data/Image.java @@ -1,5 +1,5 @@ /* - * Sone - Image.java - Copyright © 2011 David Roden + * Sone - Image.java - Copyright © 2011–2012 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,6 +34,9 @@ public class Image implements Fingerprintable { /** The Sone the image belongs to. */ private Sone sone; + /** The album this image belongs to. */ + private Album album; + /** The request key of the image. */ private String key; @@ -102,12 +105,35 @@ 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; } /** + * Returns the album this image belongs to. + * + * @return The album this image belongs to + */ + public Album getAlbum() { + return album; + } + + /** + * Sets the album this image belongs to. The album of an image can only be + * set once, and it is usually called by {@link Album#addImage(Image)}. + * + * @param album + * The album this image belongs to + * @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(); + this.album = album; + return this; + } + + /** * Returns the request key of this image. * * @return The request key of this image @@ -125,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; } @@ -161,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; } @@ -184,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; } @@ -207,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; } @@ -274,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); + } + }