INitial checkin of a streamable version of an ArrayIntSet. I like sets.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2938 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// $Id: StreamableArrayIntSet.java,v 1.1 2004/01/17 01:14:12 eric Exp $
|
||||
|
||||
package com.threerings.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.samskivert.util.ArrayIntSet;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamable;
|
||||
|
||||
/**
|
||||
* A {@link ArrayIntSet} extension that can be streamed.
|
||||
*/
|
||||
public class StreamableArrayIntSet extends ArrayIntSet
|
||||
implements Streamable
|
||||
{
|
||||
|
||||
// documentation inherited
|
||||
public StreamableArrayIntSet (int[] values)
|
||||
{
|
||||
super(values);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public StreamableArrayIntSet (int initialCapacity)
|
||||
{
|
||||
super(initialCapacity);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public StreamableArrayIntSet ()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes our custom streamable fields.
|
||||
*/
|
||||
public void writeObject (ObjectOutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
int size = size();
|
||||
out.writeInt(size);
|
||||
Iterator itr = iterator();
|
||||
while (itr.hasNext()) {
|
||||
int value = ((Integer)itr.next()).intValue();
|
||||
out.writeInt(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads our custom streamable fields.
|
||||
*/
|
||||
public void readObject (ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException
|
||||
{
|
||||
int size = in.readInt();
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
add(in.readInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user