X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FLinkPart.java;h=f516f8715f262bdf100cd5ad0a2990f6a2c8c6e8;hb=3daa6507da051b82c0e56b2299352e6307288864;hp=d911bbd5f0d17fbbf6d6e0e498e9268e778ca451;hpb=ab7fada54ed08b0a8d9ce9c606cbea29c3c3f819;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/text/LinkPart.java b/src/main/java/net/pterodactylus/sone/text/LinkPart.java index d911bbd..f516f87 100644 --- a/src/main/java/net/pterodactylus/sone/text/LinkPart.java +++ b/src/main/java/net/pterodactylus/sone/text/LinkPart.java @@ -1,5 +1,5 @@ /* - * Sone - LinkPart.java - Copyright © 2011 David Roden + * Sone - LinkPart.java - Copyright © 2011–2013 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,21 +17,48 @@ package net.pterodactylus.sone.text; +import static com.google.common.base.Objects.equal; + /** - * TODO + * {@link Part} implementation that can hold a link. A link contains of three + * attributes: the link itself, the text that is shown instead of the link, and + * an explanatory text that can be displayed e.g. as a tooltip. * * @author David ‘Bombe’ Roden */ public class LinkPart implements Part { + /** The link of this part. */ private final String link; + + /** The text of this part. */ private final String text; + + /** The title of this part. */ private final String title; + /** + * Creates a new link part. + * + * @param link + * The link of the link part + * @param text + * The text of the link part + */ public LinkPart(String link, String text) { this(link, text, text); } + /** + * Creates a new link part. + * + * @param link + * The link of the link part + * @param text + * The text of the link part + * @param title + * The title of the link part + */ public LinkPart(String link, String text, String title) { this.link = link; this.text = text; @@ -42,16 +69,55 @@ public class LinkPart implements Part { // ACCESSORS // + /** + * Returns the link of this part. + * + * @return The link of this part + */ public String getLink() { return link; } + /** + * Returns the title of this part. + * + * @return The title of this part + */ + public String getTitle() { + return title; + } + + @Override + public boolean isPlainText() { + return false; + } + + @Override + public boolean isFreenetLink() { + return false; + } + + // + // PART METHODS + // + + @Override public String getText() { return text; } - public String getTitle() { - return title; + @Override + public int hashCode() { + return getLink().hashCode() ^ (getTitle().hashCode() << 16) ^ getText().hashCode(); + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof LinkPart)) { + return false; + } + LinkPart linkPart = (LinkPart) object; + return equal(getLink(), linkPart.getLink()) && equal(getText(), linkPart.getText()) && equal(getTitle(), linkPart.getTitle()); } }