From: David ‘Bombe’ Roden Date: Fri, 8 Nov 2013 17:45:28 +0000 (+0100) Subject: Override Object methods. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=44698a668db8fb25f38b024ff6204593cd3bc451;p=Sone.git Override Object methods. --- 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()); + } + }