X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FPostShell.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FPostShell.java;h=0000000000000000000000000000000000000000;hb=48d8d875299dcbcaf24912c58960b7a1c070d22b;hp=05b0045c3e0a31d566741ce99354719f43a3a705;hpb=6a0938d8f6fdf9dbc45f03384a3cd83efeef022c;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/PostShell.java b/src/main/java/net/pterodactylus/sone/data/PostShell.java deleted file mode 100644 index 05b0045..0000000 --- a/src/main/java/net/pterodactylus/sone/data/PostShell.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Sone - PostShell.java - Copyright © 2010 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.data; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; - -import net.pterodactylus.util.logging.Logging; - -/** - * {@link Shell} around a {@link Post} that has not yet been retrieved from - * Freenet. - * - * @author David ‘Bombe’ Roden - */ -public class PostShell extends Post implements Shell { - - /** The logger. */ - private static final Logger logger = Logging.getLogger(PostShell.class); - - /** The shell creator. */ - public static final ShellCreator creator = new ShellCreator() { - - @Override - public Shell createShell(String id) { - return new PostShell().setId(id); - } - }; - - /** The GUID of the post. */ - private UUID id; - - /** The Sone this post belongs to. */ - private Sone sone; - - /** The time of the post (in milliseconds since Jan 1, 1970 UTC). */ - private Long time; - - /** The text of the post. */ - private String text; - - /** The replies that have been loaded for this post. */ - private final Set replies = new HashSet(); - - /** - * Creates a new post shell. - */ - public PostShell() { - super(null, null); - } - - // - // ACCESSORS - // - - /** - * Returns the ID of the post. - * - * @return The ID of the post - */ - @Override - public String getId() { - return id.toString(); - } - - /** - * Sets the ID of the post. - * - * @param id - * The ID of the post - * @return This post shell (for method chaining) - */ - public PostShell setId(String id) { - try { - this.id = UUID.fromString(id); - } catch (IllegalArgumentException iae1) { - logger.log(Level.WARNING, "Invalid ID: “" + id + "”.", iae1); - this.id = UUID.randomUUID(); - } - return this; - } - - /** - * Returns the Sone this post belongs to. - * - * @return The Sone of this post - */ - @Override - public Sone getSone() { - return sone; - } - - /** - * Sets the Sone the post belongs to. - * - * @param sone - * The Sone the post belongs to - * @return This post shell (for method chaining) - */ - public PostShell setSone(Sone sone) { - this.sone = sone; - return this; - } - - /** - * Returns the time of the post. - * - * @return The time of the post (in milliseconds since Jan 1, 1970 UTC) - */ - @Override - public long getTime() { - return (time != null) ? time : 0; - } - - /** - * Sets the time of the post. - * - * @param time - * The time of the post (in milliseconds since Jan 1, 1970 UTC) - * @return This post shell (for method chaining) - */ - public PostShell setTime(long time) { - this.time = time; - return this; - } - - /** - * Returns the text of the post. - * - * @return The text of the post - */ - @Override - public String getText() { - return text; - } - - /** - * Sets the text of the post. - * - * @param text - * The text of the post. - * @return This post shell (for method chaining) - */ - public PostShell setText(String text) { - this.text = text; - return this; - } - - /** - * Returns all replies to this post in unspecified order. - * - * @return All replies to this post - */ - @Override - public List getReplies() { - List sortedReplies = new ArrayList(replies); - Collections.sort(sortedReplies, new Comparator() { - - @Override - public int compare(Reply leftReply, Reply rightReply) { - return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, leftReply.getTime() - rightReply.getTime())); - } - - }); - return sortedReplies; - } - - /** - * Adds a reply to this post. The reply will not be added if its - * {@link Reply#getPost() post} is not equal to this post. - * - * @param reply - * The reply to add - */ - @Override - public void addReply(Reply reply) { - if (reply.getPost().equals(this)) { - replies.add(reply); - } - } - - /** - * Removes a reply from this post. - * - * @param reply - * The reply to remove - */ - @Override - public void removeReply(Reply reply) { - if (reply.getPost().equals(this)) { - replies.remove(reply); - } - } - - // - // INTERFACE Shell - // - - /** - * {@inheritDoc} - */ - @Override - public boolean canUnshell() { - return (id != null) && (sone != null) && (!(sone instanceof Shell)) && (time != null) && (text != null); - } - - /** - * {@inheritDoc} - */ - @Override - public Post getShelled() { - if (canUnshell()) { - Post post = new Post(id, sone, time, text); - for (Reply reply : replies) { - post.addReply(reply); - } - } - return this; - } - -}