From 63c32a955bb06e5b3c92f87f62b9914bd9606281 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 1 Jan 2011 14:26:50 +0100 Subject: [PATCH] Add link to parent album. --- .../java/net/pterodactylus/sone/data/Album.java | 43 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/data/Album.java b/src/main/java/net/pterodactylus/sone/data/Album.java index d53ba6e..62357d1 100644 --- a/src/main/java/net/pterodactylus/sone/data/Album.java +++ b/src/main/java/net/pterodactylus/sone/data/Album.java @@ -42,6 +42,9 @@ public class Album { /** The images in this album. */ private final List images = new ArrayList(); + /** The parent album. */ + private Album parent; + /** The name of this album. */ private String name; @@ -110,8 +113,9 @@ public class Album { * The album to add */ public void addAlbum(Album album) { - Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.sone, sone).check(); + Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.sone, sone).isNull("Album Parent", album.parent).check(); albums.add(album); + album.setParent(this); } /** @@ -121,8 +125,9 @@ public class Album { * The album to remove */ public void removeAlbum(Album album) { - Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.sone, sone).check(); + Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.sone, sone).isEqual("Album Parent", album.parent, this).check(); albums.remove(album); + album.removeParent(); } /** @@ -157,6 +162,40 @@ public class Album { } /** + * Returns the parent album of this album. + * + * @return The parent album of this album, or {@code null} if this album + * does not have a parent + */ + public Album getParent() { + return parent; + } + + /** + * Sets the parent album of this album. + * + * @param parent + * The new parent album of this album + * @return This album + */ + protected Album setParent(Album parent) { + Validation.begin().isNotNull("Album Parent", parent).check(); + this.parent = parent; + return this; + } + + /** + * Removes the parent album of this album. + * + * @return This album + */ + protected Album removeParent() { + Validation.begin().isNotNull("Album Parent", parent).check(); + this.parent = null; + return this; + } + + /** * Returns the name of this album. * * @return The name of this album -- 2.7.4