From: David ‘Bombe’ Roden Date: Thu, 14 Mar 2013 19:04:06 +0000 (+0100) Subject: Override hashCode(), equals(), and toString(). X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=abbc1761cc1ff6eb1b4a68b73eaa1064233b4d6b;p=sonitus.git Override hashCode(), equals(), and toString(). --- diff --git a/src/main/java/net/pterodactylus/sonitus/data/Format.java b/src/main/java/net/pterodactylus/sonitus/data/Format.java index a06889f..84a070d 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Format.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Format.java @@ -81,4 +81,27 @@ public class Format { return encoding; } + // + // OBJECT METHODS + // + + @Override + public int hashCode() { + return (channels << 16) ^ frequency ^ encoding.hashCode(); + } + + @Override + public boolean equals(Object object) { + if ((object == null) || (getClass() != object.getClass())) { + return false; + } + Format format = (Format) object; + return (format.channels == channels) && (format.frequency == frequency) && format.encoding.equals(encoding()); + } + + @Override + public String toString() { + return String.format("%d Channels, %d Hz, %s", channels, frequency, encoding); + } + }