Made occupant info into a simple streamable object because it was
screaming out for it. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1271 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
//
|
||||
// $Id: OccupantInfo.java,v 1.6 2002/03/18 23:21:26 mdb Exp $
|
||||
// $Id: OccupantInfo.java,v 1.7 2002/04/17 22:19:40 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;
|
||||
import com.threerings.presents.io.SimpleStreamableObject;
|
||||
|
||||
/**
|
||||
* The occupant info object contains all of the information about an
|
||||
@@ -26,8 +23,13 @@ import com.threerings.presents.dobj.DSet;
|
||||
* that if derived classes add non-primitive attributes, they are
|
||||
* responsible for adding the code to clone those attributes when a clone
|
||||
* is requested.
|
||||
*
|
||||
* <p> Note also that this class extends {@link SimpleStreamableObject}
|
||||
* which means that public data members will automatically be serialized,
|
||||
* but if any non-public or data members are added, code must be added to
|
||||
* serialize them when this object is streamed.
|
||||
*/
|
||||
public class OccupantInfo
|
||||
public class OccupantInfo extends SimpleStreamableObject
|
||||
implements DSet.Entry, Cloneable
|
||||
{
|
||||
/** The body object id of this occupant (and our entry key). */
|
||||
@@ -59,43 +61,4 @@ public class OccupantInfo
|
||||
throw new RuntimeException("WTF? " + cnse);
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
//
|
||||
// $Id: SpotOccupantInfo.java,v 1.1 2001/12/14 00:12:32 mdb Exp $
|
||||
// $Id: SpotOccupantInfo.java,v 1.2 2002/04/17 22:19:40 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.spot.data;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
import com.threerings.crowd.data.OccupantInfo;
|
||||
|
||||
/**
|
||||
@@ -18,27 +14,4 @@ public class SpotOccupantInfo extends OccupantInfo
|
||||
/** The id of the location occupied by this user or -1 if they occupy
|
||||
* no location. */
|
||||
public int locationId;
|
||||
|
||||
// documentation inherited
|
||||
public void writeTo (DataOutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
super.writeTo(out);
|
||||
out.writeInt(locationId);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void readFrom (DataInputStream in)
|
||||
throws IOException
|
||||
{
|
||||
super.readFrom(in);
|
||||
locationId = in.readInt();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void toString (StringBuffer buf)
|
||||
{
|
||||
super.toString(buf);
|
||||
buf.append(", locId=").append(locationId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user