From 75dec3ceb1a632501c94d2901d9915b4051bab58 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 5 Jun 2013 06:26:58 +0200 Subject: [PATCH] Add equals() method that ignores the comment of the content metadata. --- .../net/pterodactylus/sonitus/data/ContentMetadata.java | 17 +++++++++++++++++ .../java/net/pterodactylus/sonitus/data/Metadata.java | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/main/java/net/pterodactylus/sonitus/data/ContentMetadata.java b/src/main/java/net/pterodactylus/sonitus/data/ContentMetadata.java index 36194e4..9263aee 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/ContentMetadata.java +++ b/src/main/java/net/pterodactylus/sonitus/data/ContentMetadata.java @@ -193,6 +193,23 @@ public class ContentMetadata { 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()); + } + // // OBJECT METHODS // diff --git a/src/main/java/net/pterodactylus/sonitus/data/Metadata.java b/src/main/java/net/pterodactylus/sonitus/data/Metadata.java index 61c0100..da0aadc 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Metadata.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Metadata.java @@ -236,6 +236,23 @@ public class Metadata { return String.format("%s%s", title(), comment().isPresent() ? String.format(" (%s)", comment().get()) : ""); } + /** + * Returns whether this 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 Metadata)) { + return false; + } + Metadata metadata = (Metadata) object; + return formatMetadata.equals(metadata.formatMetadata) && contentMetadata.equalsIgnoreComment(metadata.contentMetadata); + } + // // OBJECT METHODS // -- 2.7.4