X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FAlbum.java;h=bf8f3ec41a1eed136880f16707181f4affbfc054;hp=67bfefdc4f0e78c4bb32bd7292260ae6bee1124c;hb=HEAD;hpb=fef93a83c728ca853ea93872e870130512af3fcb diff --git a/src/main/java/net/pterodactylus/sone/data/Album.java b/src/main/java/net/pterodactylus/sone/data/Album.java index 67bfefd..bf8f3ec 100644 --- a/src/main/java/net/pterodactylus/sone/data/Album.java +++ b/src/main/java/net/pterodactylus/sone/data/Album.java @@ -1,5 +1,5 @@ /* - * Sone - Album.java - Copyright © 2011 David Roden + * Sone - Album.java - Copyright © 2011–2020 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 @@ -17,154 +17,194 @@ package net.pterodactylus.sone.data; -import java.util.ArrayList; import java.util.List; -import java.util.UUID; /** * Container for images that can also contain nested {@link Album}s. - * - * @author David ‘Bombe’ Roden */ -public class Album { +public interface Album extends Identified, Fingerprintable { - /** The ID of this album. */ - private final String id; + /** + * Returns the ID of this album. + * + * @return The ID of this album + */ + String getId(); - /** The Sone this album belongs to. */ - private final Sone sone; + /** + * Returns the Sone this album belongs to. + * + * @return The Sone this album belongs to + */ + Sone getSone(); - /** Nested albums. */ - private final List albums = new ArrayList(); + /** + * Returns the nested albums. + * + * @return The nested albums + */ + List getAlbums(); - /** The images in this album. */ - private final List images = new ArrayList(); + /** + * Adds an album to this album. + * + * @param album + * The album to add + */ + void addAlbum(Album album); - /** The name of this album. */ - private String name; + /** + * Removes an album from this album. + * + * @param album + * The album to remove + */ + void removeAlbum(Album album); - /** The description of this album. */ - private String description; + /** + * Moves the given album up in this album’s albums. If the album is already the + * first album, nothing happens. + * + * @param album + * The album to move up + * @return The album that the given album swapped the place with, or + * null if the album did not change its place + */ + Album moveAlbumUp(Album album); /** - * Creates a new album with a random ID. + * Moves the given album down in this album’s albums. If the album is already + * the last album, nothing happens. * - * @param sone - * The Sone this album belongs to + * @param album + * The album to move down + * @return The album that the given album swapped the place with, or + * null if the album did not change its place */ - public Album(Sone sone) { - this(UUID.randomUUID().toString(), sone); - } + Album moveAlbumDown(Album album); /** - * Creates a new album with the given ID. + * Returns the images in this album. * - * @param id - * The ID of the album - * @param sone - * The Sone this album belongs to + * @return The images in this album */ - public Album(String id, Sone sone) { - this.id = id; - this.sone = sone; - } + List getImages(); - // - // ACCESSORS - // + /** + * Adds the given image to this album. + * + * @param image + * The image to add + */ + void addImage(Image image); /** - * Returns the ID of this album. + * Removes the given image from this album. * - * @return The ID of this album + * @param image + * The image to remove */ - public String getId() { - return id; - } + void removeImage(Image image); /** - * Returns the Sone this album belongs to. + * Moves the given image up in this album’s images. If the image is already the + * first image, nothing happens. * - * @return The Sone this album belongs to + * @param image + * The image to move up + * @return The image that the given image swapped the place with, or + * null if the image did not change its place */ - public Sone getSone() { - return sone; - } + Image moveImageUp(Image image); /** - * Returns the nested albums. + * Moves the given image down in this album’s images. If the image is already + * the last image, nothing happens. * - * @return The nested albums + * @param image + * The image to move down + * @return The image that the given image swapped the place with, or + * null if the image did not change its place */ - public List getNestedAlbums() { - return new ArrayList(albums); - } + Image moveImageDown(Image image); /** - * Returns the images in this album. + * Returns whether this album contains any other albums or images. * - * @return The images in this album + * @return {@code true} if this album is empty, {@code false} otherwise */ - public List getImages() { - return new ArrayList(images); - } + boolean isEmpty(); /** - * Returns the name of this album. + * Returns whether this album is an identitiy’s root album. * - * @return The name of this album + * @return {@code true} if this album is an identity’s root album, {@code + * false} otherwise */ - public String getName() { - return name; - } + boolean isRoot(); + + /** + * 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 + */ + Album getParent(); /** - * Sets the name of this album. + * Sets the parent album of this album. * - * @param name - * The name of this album + * @param parent + * The new parent album of this album * @return This album */ - public Album setName(String name) { - this.name = name; - return this; - } + Album setParent(Album parent); + + /** + * Removes the parent album of this album. + * + * @return This album + */ + Album removeParent(); + + /** + * Returns the title of this album. + * + * @return The title of this album + */ + String getTitle(); /** * Returns the description of this album. * * @return The description of this album */ - public String getDescription() { - return description; - } + String getDescription(); /** - * Sets the description of this album. + * Returns a modifier for this album. * - * @param description - * The description of this album - * @return This album + * @return A modifier for this album + * @throws IllegalStateException + * if this album can not be modified */ - public Album setDescription(String description) { - this.description = description; - return this; - } - - // - // OBJECT METHODS - // + Modifier modify() throws IllegalStateException; /** - * {@inheritDoc} + * Allows modifying an album. Modifications are only performed once {@link + * #update()} has succesfully returned a new album with the modifications + * made. */ - @Override - public boolean equals(Object object) { - if (!(object instanceof Album)) { - return false; - } - Album album = (Album) object; - return sone.equals(album.sone) && id.equals(album.id); + interface Modifier { + + Modifier setTitle(String title); + + Modifier setDescription(String description); + + Album update() throws IllegalStateException; + + class AlbumTitleMustNotBeEmpty extends IllegalStateException { } + } }