projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Only add an album if it doesn’t yet exist.
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
data
/
Album.java
diff --git
a/src/main/java/net/pterodactylus/sone/data/Album.java
b/src/main/java/net/pterodactylus/sone/data/Album.java
index
601e68d
..
e3b33de
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/Album.java
+++ b/
src/main/java/net/pterodactylus/sone/data/Album.java
@@
-45,8
+45,8
@@
public class Album implements Fingerprintable {
/** The parent album. */
private Album parent;
/** The parent album. */
private Album parent;
- /** The
nam
e of this album. */
- private String
nam
e;
+ /** The
titl
e of this album. */
+ private String
titl
e;
/** The description of this album. */
private String description;
/** The description of this album. */
private String description;
@@
-103,7
+103,7
@@
public class Album implements Fingerprintable {
* @return This album
*/
public Album setSone(Sone sone) {
* @return This album
*/
public Album setSone(Sone sone) {
- Validation.begin().isN
ull("Current Album Owner", this.sone).isNotNull("New Album Owner"
, sone).check();
+ Validation.begin().isN
otNull("New Album Owner", sone).isEither("Old Album Owner", this.sone, null
, sone).check();
this.sone = sone;
return this;
}
this.sone = sone;
return this;
}
@@
-124,9
+124,11
@@
public class Album implements Fingerprintable {
* The album to add
*/
public void addAlbum(Album album) {
* The album to add
*/
public void addAlbum(Album album) {
- Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.sone, sone).isNull("Album Parent", album.parent).check();
- albums.add(album);
+ Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.sone, sone).isEither("Old Album Parent", this.parent, null, album.parent).check();
album.setParent(this);
album.setParent(this);
+ if (!albums.contains(album)) {
+ albums.add(album);
+ }
}
/**
}
/**
@@
-158,7
+160,10
@@
public class Album implements Fingerprintable {
*/
public void addImage(Image image) {
Validation.begin().isNotNull("Image", image).check().isNotNull("Image Owner", image.getSone()).check().isEqual("Image Owner", image.getSone(), sone).check();
*/
public void addImage(Image image) {
Validation.begin().isNotNull("Image", image).check().isNotNull("Image Owner", image.getSone()).check().isEqual("Image Owner", image.getSone(), sone).check();
- images.add(image);
+ image.setAlbum(this);
+ if (!images.contains(image)) {
+ images.add(image);
+ }
}
/**
}
/**
@@
-186,6
+191,15
@@
public class Album implements Fingerprintable {
}
/**
}
/**
+ * Returns whether this album contains any other albums or images.
+ *
+ * @return {@code true} if this album is empty, {@code false} otherwise
+ */
+ public boolean isEmpty() {
+ return albums.isEmpty() && images.isEmpty();
+ }
+
+ /**
* Returns the parent album of this album.
*
* @return The parent album of this album, or {@code null} if this album
* Returns the parent album of this album.
*
* @return The parent album of this album, or {@code null} if this album
@@
-214,30
+228,29
@@
public class Album implements Fingerprintable {
* @return This album
*/
protected Album removeParent() {
* @return This album
*/
protected Album removeParent() {
- Validation.begin().isNotNull("Album Parent", parent).check();
this.parent = null;
return this;
}
/**
this.parent = null;
return this;
}
/**
- * Returns the
nam
e of this album.
+ * Returns the
titl
e of this album.
*
*
- * @return The
nam
e of this album
+ * @return The
titl
e of this album
*/
*/
- public String get
Nam
e() {
- return
nam
e;
+ public String get
Titl
e() {
+ return
titl
e;
}
/**
}
/**
- * Sets the
nam
e of this album.
+ * Sets the
titl
e of this album.
*
*
- * @param
nam
e
- * The
nam
e of this album
+ * @param
titl
e
+ * The
titl
e of this album
* @return This album
*/
* @return This album
*/
- public Album set
Name(String nam
e) {
- Validation.begin().isNotNull("Album
Name", nam
e).check();
- this.
name = nam
e;
+ public Album set
Title(String titl
e) {
+ Validation.begin().isNotNull("Album
Title", titl
e).check();
+ this.
title = titl
e;
return this;
}
return this;
}
@@
-275,7
+288,7
@@
public class Album implements Fingerprintable {
StringBuilder fingerprint = new StringBuilder();
fingerprint.append("Album(");
fingerprint.append("ID(").append(id).append(')');
StringBuilder fingerprint = new StringBuilder();
fingerprint.append("Album(");
fingerprint.append("ID(").append(id).append(')');
- fingerprint.append("
Name(").append(nam
e).append(')');
+ fingerprint.append("
Title(").append(titl
e).append(')');
fingerprint.append("Description(").append(description).append(')');
/* add nested albums. */
fingerprint.append("Description(").append(description).append(')');
/* add nested albums. */
@@
-288,7
+301,9
@@
public class Album implements Fingerprintable {
/* add images. */
fingerprint.append("Images(");
for (Image image : images) {
/* add images. */
fingerprint.append("Images(");
for (Image image : images) {
- fingerprint.append(image.getFingerprint());
+ if (image.isInserted()) {
+ fingerprint.append(image.getFingerprint());
+ }
}
fingerprint.append(')');
}
fingerprint.append(')');