Rework the text parser.
[Sone.git] / src / main / java / net / pterodactylus / sone / text / PostPart.java
index 1e0773d..bf974e1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - PostLinkPart.java - Copyright © 2011 David Roden
+ * Sone - PostPart.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
 
 package net.pterodactylus.sone.text;
 
+import static com.google.common.base.Objects.equal;
+
 import net.pterodactylus.sone.data.Post;
 
 /**
- * TODO
+ * {@link Part} implementation that stores a reference to a {@link Post}.
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
 public class PostPart implements Part {
 
+       /** The post this part refers to. */
        private final Post post;
 
+       /**
+        * Creates a new post part.
+        *
+        * @param post
+        *            The referenced post
+        */
        public PostPart(Post post) {
                this.post = post;
        }
 
+       //
+       // ACCESSORS
+       //
+
+       @Override
+       public boolean isPlainText() {
+               return false;
+       }
+
+       @Override
+       public boolean isFreenetLink() {
+               return false;
+       }
+
+       /**
+        * Returns the post referenced by this part.
+        *
+        * @return The post referenced by this part
+        */
        public Post getPost() {
                return post;
        }
 
+       //
+       // PART METHODS
+       //
+
+       @Override
+       public String getText() {
+               return post.getText();
+       }
+
+       @Override
+       public int hashCode() {
+               return getPost().hashCode();
+       }
+
+       @Override
+       public boolean equals(Object object) {
+               if (!(object instanceof PostPart)) {
+                       return false;
+               }
+               PostPart postPart = (PostPart) object;
+               return equal(getPost(), postPart.getPost());
+       }
+
 }