From 44698a668db8fb25f38b024ff6204593cd3bc451 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 8 Nov 2013 18:45:28 +0100 Subject: [PATCH] Override Object methods. --- .../pterodactylus/sone/text/FreenetLinkPart.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/text/FreenetLinkPart.java b/src/main/java/net/pterodactylus/sone/text/FreenetLinkPart.java index c667f38..c606149 100644 --- a/src/main/java/net/pterodactylus/sone/text/FreenetLinkPart.java +++ b/src/main/java/net/pterodactylus/sone/text/FreenetLinkPart.java @@ -17,6 +17,11 @@ package net.pterodactylus.sone.text; +import static com.google.common.base.Objects.equal; +import static java.lang.String.format; + +import com.google.common.base.Objects; + /** * {@link LinkPart} implementation that stores an additional attribute: if the * link is an SSK or USK link and the post was created by an identity that owns @@ -73,4 +78,23 @@ public class FreenetLinkPart extends LinkPart { return trusted; } + @Override + public int hashCode() { + return (getLink().hashCode() << 16) ^ (getText().hashCode() << 8 ) ^ getTitle().hashCode() ^ (isTrusted() ? -1 : 0); + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof FreenetLinkPart)) { + return false; + } + FreenetLinkPart freenetLinkPart = (FreenetLinkPart) object; + return equal(getLink(), freenetLinkPart.getLink()) && equal(getText(), freenetLinkPart.getText()) && equal(getTitle(), freenetLinkPart.getTitle()) && (isTrusted() == freenetLinkPart.isTrusted()); + } + + @Override + public String toString() { + return format("FreenetLink(link=%s, text=%s, title=%s, trusted=%s)", getLink(), getText(), getTitle(), isTrusted()); + } + } -- 2.7.4