Commits

Rhys ! committed 04b3c11 Draft

additional Javadoc

  • Participants
  • Parent commits c8528b3

Comments (0)

Files changed (7)

src/org/bert_rpc/Atom.java

 package org.bert_rpc;
 
 /**
- * A BERT atom.
+ * A BERT atom: a literal, a constant with name.
  */
 public class Atom {
-    public final String identifier;
+    private final String name;
 
-    public Atom(String identifier) {
-        this.identifier = identifier;
+    /**
+     * Creates an atom with the specified name.
+     *
+     * @param name The name of the new atom.
+     */
+    public Atom(String name) {
+        this.name = name;
+    }
+
+    /**
+     * Gets the name of this atom.
+     *
+     * @return The name of this atom.
+     */
+    public String getName() {
+        return this.name;
     }
 
     @Override
     public String toString() {
-        return "'" + this.identifier;
+        return "'" + this.name;
     }
 
     @Override
                 this.equals((Atom)other);
     }
 
+    /**
+     * Indicates whether some other atom has the same name as this one.
+     *
+     * @param other The atom to compare this one to.
+     * @return true if other and this atom have the same name, false otherwise.
+     */
     public boolean equals(Atom other) {
-        return this.identifier.equals(other.identifier);
+        return other != null && this.name.equals(other.name);
     }
 
     @Override
     public int hashCode() {
-        return 524287 * this.identifier.hashCode();
+        return 524287 * this.name.hashCode();
     }
 }

src/org/bert_rpc/Bert.java

 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 
 /**
  * BERT static convenience methods.
  */
 public class Bert {
+    private Bert() {}
+
     /**
      * Reads a single object from the provided byte array.
      *
      *
      * @see org.bert_rpc
      */
-    public static Object decode(byte[] bytes) throws DecodingException {
+    public static Object decode(final byte[] bytes) throws DecodingException {
         try {
             return new Decoder(new ByteArrayInputStream(bytes)).decode();
         } catch (IOException e) {

src/org/bert_rpc/Constants.java

 class Constants {
     public static final byte SMALL_INT = 97;
     public static final byte INT = 98;
-    public static final byte SMALL_BIGNUM = 110;
-    public static final byte LARGE_BIGNUM = 111;
+//    public static final byte SMALL_BIGNUM = 110;
+//    public static final byte LARGE_BIGNUM = 111;
     public static final byte FLOAT = 99;
     public static final byte ATOM = 100;
     public static final byte SMALL_TUPLE = 104;
     public static final byte LARGE_TUPLE = 105;
     public static final byte NIL = 106;
-    public static final byte STRING = 107;
+//    public static final byte STRING = 107;
     public static final byte LIST = 108;
     public static final byte BIN = 109;
-    public static final byte FUN = 117;
-    public static final byte NEW_FUN = 112;
+//    public static final byte FUN = 117;
+//    public static final byte NEW_FUN = 112;
     public static final int MAGIC = 131;
-    public static final int MAX_INT =  (1 << 27) -1;
-    public static final int MIN_INT = -(1 << 27);
+//    public static final int MAX_INT =  (1 << 27) -1;
+//    public static final int MIN_INT = -(1 << 27);
 
     public static final byte FLOAT_LENGTH = 31;
 

src/org/bert_rpc/Decoder.java

 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.Charset;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.regex.Pattern;
 
 /**

src/org/bert_rpc/Encoder.java

 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.*;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 import java.util.regex.Pattern;
 
 /**
 
     private void writeAtom(Atom atom) throws IOException {
         this.outputStream.writeByte(Constants.ATOM);
-        this.outputStream.writeShort(atom.identifier.length());
-        this.outputStream.writeBytes(atom.identifier);
+        this.outputStream.writeShort(atom.getName().length());
+        this.outputStream.writeBytes(atom.getName());
     }
 
     /**

src/org/bert_rpc/Tuple.java

 package org.bert_rpc;
 
-import java.util.*;
+import java.util.AbstractList;
+import java.util.Arrays;
 
 /**
- * A BERT tuple.
+ * A BERT tuple: a compound data type with a fixed number of terms.
  */
 public class Tuple extends AbstractList {
     private final Object[] contents;
 
+    /**
+     * Creates a new empty tuple.
+     */
     public Tuple() {
         this(new Object[0]);
     }
 
+    /**
+     * Creates a new tuple with the provided contents.
+     *
+     * @param contents The contents of the new tuple.
+     */
     public Tuple(Object... contents) {
         this.contents = contents;
     }
         return "Tuple(" + cs.substring(1, cs.length() - 1) + ")";
     }
 
+    /**
+     * Indicates whether some other tuple has contents equal to this one's.
+     *
+     * @param other The tuple to compare this one to.
+     * @return true if the contents of this tuple and the other are equal,
+     * false otherwise.
+     */
     public boolean equals(Tuple other) {
         return Arrays.equals(this.contents, other.contents);
     }

src/org/bert_rpc/package-info.java

  * UTF-8, since Java does not accept binary patterns.
  */
 
-package org.bert_rpc;
+package org.bert_rpc;