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