X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fdata%2FContentMetadata.java;h=9263aee64856d1e02cf26583c433b22c4c298135;hb=75dec3ceb1a632501c94d2901d9915b4051bab58;hp=cdfc4d2c826d7c30cc604599f9422472c73de500;hpb=0f20c60dd0509d91b488c2c10edf7498feeed560;p=sonitus.git diff --git a/src/main/java/net/pterodactylus/sonitus/data/ContentMetadata.java b/src/main/java/net/pterodactylus/sonitus/data/ContentMetadata.java index cdfc4d2..9263aee 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/ContentMetadata.java +++ b/src/main/java/net/pterodactylus/sonitus/data/ContentMetadata.java @@ -46,6 +46,9 @@ public class ContentMetadata { /** The all-in-one title. */ private final String title; + /** The comment. */ + private final Optional comment; + /** Creates empty content metadata. */ public ContentMetadata() { this(""); @@ -60,7 +63,7 @@ public class ContentMetadata { * if {@code title} is {@code null} */ public ContentMetadata(String title) throws NullPointerException { - this(null, null, title); + this(null, null, title, null); } /** @@ -72,7 +75,7 @@ public class ContentMetadata { * The name of the track */ public ContentMetadata(String artist, String name) { - this(artist, name, joinStrings(artist, name)); + this(artist, name, joinStrings(artist, name), null); } /** @@ -84,13 +87,16 @@ public class ContentMetadata { * The name of the track (may be null) * @param title * The title of the track + * @param comment + * The comment of the track * @throws NullPointerException * if {@code title} is {@code null} */ - private ContentMetadata(String artist, String name, String title) throws NullPointerException { + private ContentMetadata(String artist, String name, String title, String comment) throws NullPointerException { this.artist = Optional.fromNullable(artist); this.name = Optional.fromNullable(name); this.title = Preconditions.checkNotNull(title, "title must not be null"); + this.comment = Optional.fromNullable(comment); } // @@ -124,6 +130,15 @@ public class ContentMetadata { return title; } + /** + * Returns the comment of the track, if it has been set. + * + * @return The comment of the track + */ + public Optional comment() { + return comment; + } + // // ACTIONS // @@ -138,7 +153,7 @@ public class ContentMetadata { * @return The new content metadata */ public ContentMetadata artist(String artist) { - return new ContentMetadata(artist, name().orNull(), joinStrings(artist, name().orNull())); + return new ContentMetadata(artist, name().orNull(), joinStrings(artist, name().orNull()), comment.orNull()); } /** @@ -151,7 +166,7 @@ public class ContentMetadata { * @return The new content metadata */ public ContentMetadata name(String name) { - return new ContentMetadata(artist().orNull(), name, joinStrings(artist().orNull(), name)); + return new ContentMetadata(artist().orNull(), name, joinStrings(artist().orNull(), name), comment.orNull()); } /** @@ -163,7 +178,36 @@ public class ContentMetadata { * @return The new content metadata */ public ContentMetadata title(String title) { - return new ContentMetadata(artist().orNull(), name().orNull(), title); + return new ContentMetadata(artist().orNull(), name().orNull(), title, comment.orNull()); + } + + /** + * Creates new content metadata that is a copy of this content metadata but + * with the comment changed. + * + * @param comment + * The comment + * @return The new content metadata + */ + public ContentMetadata comment(String comment) { + return new ContentMetadata(artist().orNull(), name().orNull(), title(), comment); + } + + /** + * Returns whether this content metadata object equals the given object if the + * comments of this and the given object are ignored. + * + * @param object + * The object to compare to this one + * @return {@code true} if the given object and this object are equal if the + * comments are ignored, {@code false} otherwise + */ + public boolean equalsIgnoreComment(Object object) { + if (!(object instanceof ContentMetadata)) { + return false; + } + ContentMetadata contentMetadata = (ContentMetadata) object; + return artist().equals(contentMetadata.artist()) && name().equals(contentMetadata.name()) && title().equals(contentMetadata.title()); } // @@ -172,7 +216,7 @@ public class ContentMetadata { @Override public int hashCode() { - return artist().hashCode() ^ name().hashCode() ^ title().hashCode(); + return artist().hashCode() ^ name().hashCode() ^ title().hashCode() ^ comment().hashCode(); } @Override @@ -181,12 +225,12 @@ public class ContentMetadata { return false; } ContentMetadata contentMetadata = (ContentMetadata) object; - return artist().equals(contentMetadata.artist()) && name().equals(contentMetadata.name()) && title().equals(contentMetadata.title()); + return artist().equals(contentMetadata.artist()) && name().equals(contentMetadata.name()) && title().equals(contentMetadata.title()) && comment().equals(contentMetadata.comment()); } @Override public String toString() { - return title; + return String.format("%s%s", title(), comment().isPresent() ? String.format(" (%s)", comment().get()) : ""); } //