2 * Sone - FreenetLinkPart.java - Copyright © 2011–2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.text;
20 import static com.google.common.base.Objects.equal;
21 import static java.lang.String.format;
23 import com.google.common.base.Objects;
26 * {@link LinkPart} implementation that stores an additional attribute: if the
27 * link is an SSK or USK link and the post was created by an identity that owns
28 * the keyspace in question.
30 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
32 public class FreenetLinkPart extends LinkPart {
34 /** Whether the link is trusted. */
35 private final boolean trusted;
38 * Creates a new freenet link part.
41 * The link of the part
43 * The text of the part
45 * {@code true} if the link is trusted, {@code false} otherwise
47 public FreenetLinkPart(String link, String text, boolean trusted) {
48 this(link, text, text, trusted);
52 * Creates a new freenet link part.
55 * The link of the part
57 * The text of the part
59 * The title of the part
61 * {@code true} if the link is trusted, {@code false} otherwise
63 public FreenetLinkPart(String link, String text, String title, boolean trusted) {
64 super(link, text, title);
65 this.trusted = trusted;
73 * Returns whether the link is trusted.
75 * @return {@code true} if the link is trusted, {@code false} otherwise
77 public boolean isTrusted() {
82 public boolean isFreenetLink() {
87 public int hashCode() {
88 return (getLink().hashCode() << 16) ^ (getText().hashCode() << 8 ) ^ getTitle().hashCode() ^ (isTrusted() ? -1 : 0);
92 public boolean equals(Object object) {
93 if (!(object instanceof FreenetLinkPart)) {
96 FreenetLinkPart freenetLinkPart = (FreenetLinkPart) object;
97 return equal(getLink(), freenetLinkPart.getLink()) && equal(getText(), freenetLinkPart.getText()) && equal(getTitle(), freenetLinkPart.getTitle()) && (isTrusted() == freenetLinkPart.isTrusted());
101 public String toString() {
102 return format("FreenetLink(link=%s, text=%s, title=%s, trusted=%s)", getLink(), getText(), getTitle(), isTrusted());