- public List<Album> getAllAlbums() {
- List<Album> flatAlbums = new ArrayList<Album>();
- flatAlbums.addAll(albums);
- int lastAlbumIndex = 0;
- while (lastAlbumIndex < flatAlbums.size()) {
- int previousAlbumCount = flatAlbums.size();
- for (Album album : new ArrayList<Album>(flatAlbums.subList(lastAlbumIndex, flatAlbums.size()))) {
- flatAlbums.addAll(album.getAlbums());
- }
- lastAlbumIndex = previousAlbumCount;
- }
- return flatAlbums;
- }
-
- /**
- * Returns all images of a Sone. Images of a album are inserted into this
- * list before images of all child albums.
- *
- * @return The list of all images
- */
- public List<Image> getAllImages() {
- List<Image> allImages = new ArrayList<Image>();
- for (Album album : getAllAlbums()) {
- allImages.addAll(album.getImages());
- }
- return allImages;
- }
-
- /**
- * Adds an album to this Sone.
- *
- * @param album
- * The album to add
- */
- public synchronized void addAlbum(Album album) {
- Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.getSone(), this).check();
- albums.add(album);
- }
-
- /**
- * Sets the albums of this Sone.
- *
- * @param albums
- * The albums of this Sone
- */
- public synchronized void setAlbums(Collection<? extends Album> albums) {
- Validation.begin().isNotNull("Albums", albums).check();
- this.albums.clear();
- for (Album album : albums) {
- addAlbum(album);
- }
- }
-
- /**
- * Removes an album from this Sone.
- *
- * @param album
- * The album to remove
- */
- public synchronized void removeAlbum(Album album) {
- Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.getSone(), this).check();
- albums.remove(album);
- }
-
- /**
- * 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
- * <code>null</code> if the album did not change its place
- */
- public Album moveAlbumUp(Album album) {
- Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.getSone(), this).isNull("Album Parent", album.getParent()).check();
- int oldIndex = albums.indexOf(album);
- if (oldIndex <= 0) {
- return null;
- }
- albums.remove(oldIndex);
- albums.add(oldIndex - 1, album);
- return albums.get(oldIndex);
- }
-
- /**
- * Moves the given album down in this album’s albums. If the album is
- * already the last album, nothing happens.
- *
- * @param album
- * The album to move down
- * @return The album that the given album swapped the place with, or
- * <code>null</code> if the album did not change its place
- */
- public Album moveAlbumDown(Album album) {
- Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.getSone(), this).isNull("Album Parent", album.getParent()).check();
- int oldIndex = albums.indexOf(album);
- if ((oldIndex < 0) || (oldIndex >= (albums.size() - 1))) {
- return null;
- }
- albums.remove(oldIndex);
- albums.add(oldIndex + 1, album);
- return albums.get(oldIndex);
- }