/*
- * Sone - Album.java - Copyright © 2011–2013 David Roden
+ * Sone - AlbumImpl.java - Copyright © 2011–2016 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
/** The description of this album. */
private String description;
- /** The ID of the album picture. */
- private String albumImage;
-
/** Creates a new album with a random ID. */
public AlbumImpl(Sone sone) {
this(sone, UUID.randomUUID().toString());
checkArgument(equals(album.getParent()), "album must belong to this album");
int oldIndex = albums.indexOf(album);
if (oldIndex <= 0) {
- return null;
+ return album;
}
albums.remove(oldIndex);
albums.add(oldIndex - 1, album);
checkArgument(equals(album.getParent()), "album must belong to this album");
int oldIndex = albums.indexOf(album);
if ((oldIndex < 0) || (oldIndex >= (albums.size() - 1))) {
- return null;
+ return album;
}
albums.remove(oldIndex);
albums.add(oldIndex + 1, album);
image.getAlbum().removeImage(image);
}
image.setAlbum(this);
- if (imageIds.isEmpty() && (albumImage == null)) {
- albumImage = image.getId();
- }
if (!imageIds.contains(image.getId())) {
imageIds.add(image.getId());
images.put(image.getId(), image);
checkArgument(image.getSone().equals(sone), "image must belong to the same Sone as this album");
imageIds.remove(image.getId());
images.remove(image.getId());
- if (image.getId().equals(albumImage)) {
- if (images.isEmpty()) {
- albumImage = null;
- } else {
- albumImage = images.values().iterator().next().getId();
- }
- }
}
@Override
}
@Override
- public Image getAlbumImage() {
- if (albumImage == null) {
- return null;
- }
- return Optional.fromNullable(images.get(albumImage)).or(images.values().iterator().next());
- }
-
- @Override
public boolean isEmpty() {
return albums.isEmpty() && images.isEmpty();
}
private Optional<String> description = absent();
- private Optional<String> albumImage = absent();
-
@Override
public Modifier setTitle(String title) {
this.title = fromNullable(title);
}
@Override
- public Modifier setAlbumImage(String imageId) {
- this.albumImage = fromNullable(imageId);
- return this;
- }
-
- @Override
public Album update() throws IllegalStateException {
if (title.isPresent() && title.get().trim().isEmpty()) {
throw new AlbumTitleMustNotBeEmpty();
if (description.isPresent()) {
AlbumImpl.this.description = description.get();
}
- if (albumImage.isPresent()) {
- AlbumImpl.this.albumImage = albumImage.get();
- }
return AlbumImpl.this;
}
};
hash.putString("ID(").putString(id).putString(")");
hash.putString("Title(").putString(title).putString(")");
hash.putString("Description(").putString(description).putString(")");
- if (albumImage != null) {
- hash.putString("AlbumImage(").putString(albumImage).putString(")");
- }
/* add nested albums. */
hash.putString("Albums(");