- @Override
- public Modifier modify() throws IllegalStateException {
- // TODO: reenable check for local Sones
- return new Modifier() {
- private Optional<String> title = absent();
-
- private Optional<String> description = absent();
-
- private Optional<String> albumImage = absent();
-
- @Override
- public Modifier setTitle(String title) {
- this.title = fromNullable(title);
- return this;
- }
-
- @Override
- public Modifier setDescription(String description) {
- this.description = fromNullable(description);
- return this;
- }
-
- @Override
- public Modifier setAlbumImage(String imageId) {
- this.albumImage = fromNullable(imageId);
- return this;
- }
-
- @Override
- public Album update() throws IllegalStateException {
- if (title.isPresent()) {
- DefaultAlbum.this.title = title.get();
- }
- if (description.isPresent()) {
- DefaultAlbum.this.description = description.get();
- }
- if (albumImage.isPresent()) {
- DefaultAlbum.this.albumImage = albumImage.get();
- }
- return DefaultAlbum.this;
- }
- };
- }
-
- //
- // FINGERPRINTABLE METHODS
- //
-
- @Override
- public String getFingerprint() {
- Hasher hash = Hashing.sha256().newHasher();
- hash.putString("Album(");
- 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(");
- for (Album album : albums) {
- hash.putString(album.getFingerprint());
- }
- hash.putString(")");
-
- /* add images. */
- hash.putString("Images(");
- for (Image image : getImages()) {
- if (image.isInserted()) {
- hash.putString(image.getFingerprint());
- }
- }
- hash.putString(")");
-
- hash.putString(")");
- return hash.hash().toString();
- }
-
- //
- // OBJECT METHODS
- //
-
- @Override
- public int hashCode() {
- return id.hashCode();
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof DefaultAlbum)) {
- return false;
- }
- DefaultAlbum album = (DefaultAlbum) object;
- return id.equals(album.id);
- }
-