X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSoneShell.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSoneShell.java;h=0000000000000000000000000000000000000000;hb=48d8d875299dcbcaf24912c58960b7a1c070d22b;hp=9063d31827f18d79199b2281c900f2347aab996d;hpb=6a0938d8f6fdf9dbc45f03384a3cd83efeef022c;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/data/SoneShell.java b/src/main/java/net/pterodactylus/sone/data/SoneShell.java
deleted file mode 100644
index 9063d31..0000000
--- a/src/main/java/net/pterodactylus/sone/data/SoneShell.java
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
- * Sone - SoneShell.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;
-import freenet.keys.FreenetURI;
-
-/**
- * {@link Shell} around a {@link Sone} that has not yet been retrieved.
- *
- * @author David âBombeâ Roden
- */
-public class SoneShell extends Sone implements Shell {
-
- /** The logger. */
- private static final Logger logger = Logging.getLogger(SoneShell.class);
-
- /** The shell creator. */
- public static final ShellCreator creator = new ShellCreator() {
-
- @Override
- public Shell createShell(String id) {
- return new SoneShell().setId(id);
- }
- };
-
- /** A GUID for this Sone. */
- private UUID id;
-
- /** The name of this Sone. */
- private String name;
-
- /** The URI under which the Sone is stored in Freenet. */
- private FreenetURI requestUri;
-
- /** The profile of this Sone. */
- private Profile profile;
-
- /** All friend Sones. */
- private final Set friendSones = new HashSet();
-
- /** All posts. */
- private final List posts = new ArrayList();
-
- /** All replies. */
- private final Set replies = new HashSet();
-
- /**
- * Creates a new Sone shell.
- */
- public SoneShell() {
- super(null, null, null);
- }
-
- //
- // ACCESSORS
- //
-
- /**
- * Returns the ID of this Sone.
- *
- * @return The ID of this Sone
- */
- @Override
- public String getId() {
- return id.toString();
- }
-
- /**
- * Sets the ID of the Sone.
- *
- * @param id
- * The ID of the Sone
- * @return This Sone shell (for method chaining)
- */
- public SoneShell 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 name of this Sone.
- *
- * @return The name of this Sone
- */
- @Override
- public String getName() {
- return name;
- }
-
- /**
- * Sets the name of the Sone.
- *
- * @param name
- * The name of the Sone
- * @return This Sone shell (for method chaining)
- */
- public SoneShell setName(String name) {
- this.name = name;
- return this;
- }
-
- /**
- * Returns the request URI of this Sone.
- *
- * @return The request URI of this Sone
- */
- @Override
- public FreenetURI getRequestUri() {
- return requestUri;
- }
-
- /**
- * Sets the request URI of the Sone.
- *
- * @param requestUri
- * The request URI of the Sone
- * @return This Sone shell (for method chaining)
- */
- public SoneShell setRequestUri(FreenetURI requestUri) {
- this.requestUri = requestUri;
- return this;
- }
-
- /**
- * Returns a copy of the profile. If you want to update values in the
- * profile of this Sone, update the values in the returned {@link Profile}
- * and use {@link #setProfile(Profile)} to change the profile in this Sone.
- *
- * @return A copy of the profile
- */
- @Override
- public Profile getProfile() {
- return new Profile(profile);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setProfile(Profile profile) {
- this.profile = profile;
- }
-
- /**
- * Returns all friend Sones of this Sone.
- *
- * @return The friend Sones of this Sone
- */
- @Override
- public Set getFriends() {
- return Collections.unmodifiableSet(friendSones);
- }
-
- /**
- * Returns whether this Sone has the given Sone as a friend Sone.
- *
- * @param friendSone
- * The friend Sone to check for
- * @return {@code true} if this Sone has the given Sone as a friend,
- * {@code false} otherwise
- */
- @Override
- public boolean hasFriend(Sone friendSone) {
- return friendSones.contains(friendSone);
- }
-
- /**
- * Adds the given Sone as a friend Sone.
- *
- * @param friendSone
- * The friend Sone to add
- * @return This Sone (for method chaining)
- */
- @Override
- public Sone addFriend(Sone friendSone) {
- friendSones.add(friendSone);
- return this;
- }
-
- /**
- * Removes the given Sone as a friend Sone.
- *
- * @param friendSone
- * The friend Sone to remove
- * @return This Sone (for method chaining)
- */
- @Override
- public Sone removeFriend(Sone friendSone) {
- friendSones.remove(friendSone);
- return this;
- }
-
- /**
- * Returns the list of posts of this Sone, sorted by time, newest first.
- *
- * @return All posts of this Sone
- */
- @Override
- public List getPosts() {
- List sortedPosts = new ArrayList(posts);
- Collections.sort(sortedPosts, new Comparator() {
-
- @Override
- public int compare(Post leftPost, Post rightPost) {
- return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, rightPost.getTime() - leftPost.getTime()));
- }
-
- });
- return sortedPosts;
- }
-
- /**
- * Adds the given post to this Sone. The post will not be added if its
- * {@link Post#getSone() Sone} is not this Sone.
- *
- * @param post
- * The post to add
- */
- @Override
- public void addPost(Post post) {
- posts.add(post);
- }
-
- /**
- * Removes the given post from this Sone.
- *
- * @param post
- * The post to remove
- */
- @Override
- public void removePost(Post post) {
- posts.remove(post);
- }
-
- /**
- * Returns all replies this Sone made.
- *
- * @return All replies this Sone made
- */
- @Override
- public Set getReplies() {
- return Collections.unmodifiableSet(replies);
- }
-
- /**
- * Adds a reply to this Sone. If the given reply was not made by this Sone,
- * nothing is added to this Sone.
- *
- * @param reply
- * The reply to add
- */
- @Override
- public void addReply(Reply reply) {
- replies.add(reply);
- }
-
- /**
- * Removes a reply from this Sone.
- *
- * @param reply
- * The reply to remove
- */
- @Override
- public void removeReply(Reply reply) {
- replies.remove(reply);
- }
-
- //
- // INTERFACE Shell
- //
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean canUnshell() {
- return (id != null) && (name != null) && (requestUri != null) && (profile != null);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Sone getShelled() {
- if (canUnshell()) {
- Sone sone = new Sone(id, name, requestUri);
- sone.setProfile(profile);
- for (Sone friendSone : friendSones) {
- sone.addFriend(friendSone);
- }
- for (Post post : posts) {
- sone.addPost(post);
- }
- for (Reply reply : replies) {
- sone.addReply(reply);
- }
- return sone;
- }
- return this;
- }
-
-}