//
// $Id: OccupantInfo.java,v 1.4 2001/12/14 00:11:17 mdb Exp $

package com.threerings.crowd.data;

import java.io.IOException;
import java.io.DataInputStream;
import java.io.DataOutputStream;

import com.threerings.presents.dobj.DSet;

/**
 * The occupant info object contains all of the information about an
 * occupant of a place that should be shared with other occupants of the
 * place. These objects are stored in the place object itself and are
 * updated when bodies enter and exit a place. A system that builds upon
 * the Crowd framework can extend this class to include extra information
 * about their occupants. They will need to be sure to return the proper
 * class from {@link
 * com.threerings.crowd.server.PlaceManager#getOccupantInfoClass}
 * and populate their occupant info in {@link
 * com.threerings.crowd.server.PlaceManager#populateOccupantInfo}.
 */
public class OccupantInfo implements DSet.Element
{
    /** The body object id of this occupant (and our element key). */
    public Integer bodyOid;

    /** The username of this occupant. */
    public String username;

    /** Access to the body object id as an int. */
    public int getBodyOid ()
    {
        return bodyOid.intValue();
    }

    // documentation inherited
    public Object getKey ()
    {
        return bodyOid;
    }

    // documentation inherited
    public void writeTo (DataOutputStream out)
        throws IOException
    {
        out.writeInt(bodyOid.intValue());
        out.writeUTF(username);
    }

    // documentation inherited
    public void readFrom (DataInputStream in)
        throws IOException
    {
        bodyOid = new Integer(in.readInt());
        username = in.readUTF();
    }

    /**
     * Called to generate a string representation of this occupant info
     * object. This calls the overridable {@link #toString(StringBuffer)}
     * to generate that representation in a derived class friendly manner.
     */
    public String toString ()
    {
        StringBuffer buf = new StringBuffer("[");
        toString(buf);
        return buf.append("]").toString();
    }

    /**
     * Derived classes should override this and append their extra
     * occupant info to the buffer. They should of course not to forget to
     * call super.
     */
    protected void toString (StringBuffer buf)
    {
        buf.append("boid=").append(bodyOid);
        buf.append(", username=").append(username);
    }
}

@@ -26,17 +26,17 @@
 ava,v 1.
-4
+5
  2001/12
@@ -41,18 +41,18 @@
 12/1
-4 00:11:17
+5 04:20:00
  mdb
@@ -494,16 +494,26 @@
 a place.
+%0A *%0A * %3Cp%3E
  A syste
@@ -530,19 +530,16 @@
 lds upon
-%0A *
  the Cro
@@ -572,16 +572,19 @@
 is class
+%0A *
  to incl
@@ -604,19 +604,16 @@
 ormation
-%0A *
  about t
@@ -645,16 +645,19 @@
  need to
+%0A *
  be sure
@@ -677,19 +677,16 @@
 e proper
-%0A *
  class f
@@ -765,15 +765,15 @@
 ass%7D
-%0A *
  and
+%0A *
  pop
@@ -875,16 +875,250 @@
 tInfo%7D.%0A
+ *%0A * %3Cp%3E Note also that this class implements %7B@link Cloneable%7D which means%0A * that if derived classes add non-primitive attributes, they are%0A * responsible for adding the code to clone those attributes when a clone%0A * is requested.%0A
  */%0Apubl
@@ -1138,16 +1138,20 @@
 pantInfo
+%0A   
  impleme
@@ -1166,16 +1166,27 @@
 .Element
+, Cloneable
 %0A%7B%0A    /
@@ -1566,32 +1566,303 @@
 bodyOid;%0A    %7D%0A%0A
+    /**%0A     * Generates a cloned copy of this instance.%0A     */%0A    public Object clone ()%0A    %7B%0A        try %7B%0A            return super.clone();%0A        %7D catch (CloneNotSupportedException cnse) %7B%0A            throw new RuntimeException(%22WTF? %22 + cnse);%0A        %7D%0A    %7D%0A%0A
     // documenta

Add support for clone().