per mdb, IntSetStat will store a maximum of 255 entries

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@659 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Tom Conkling
2008-07-16 20:27:17 +00:00
parent 43df45be1a
commit 8f12cff519
@@ -13,19 +13,21 @@ import com.threerings.io.ObjectOutputStream;
public class IntSetStat extends Stat public class IntSetStat extends Stat
{ {
/** /**
* Constructs a new IntSetStat that will store up to Integer.MAX_VALUE ints. * Constructs a new IntSetStat that will store up to 255 ints.
*/ */
public IntSetStat () public IntSetStat ()
{ {
_maxSize = Integer.MAX_VALUE; _maxSize = MAX_MAX_SIZE;
} }
/** /**
* Constructs a new IntSetStat that will store up to maxSize ints. * Constructs a new IntSetStat that will store up to maxSize ints.
*
* @param the maximum number of ints to store in the IntSetStat. Must be <= 255.
*/ */
public IntSetStat (int maxSize) public IntSetStat (int maxSize)
{ {
_maxSize = maxSize; _maxSize = Math.min(maxSize, MAX_MAX_SIZE);
} }
/** /**
@@ -58,7 +60,7 @@ public class IntSetStat extends Stat
public void persistTo (ObjectOutputStream out, AuxDataSource aux) public void persistTo (ObjectOutputStream out, AuxDataSource aux)
throws IOException throws IOException
{ {
out.writeInt(_maxSize); out.writeByte(_maxSize - 128);
out.writeInt(_intSet.size()); out.writeInt(_intSet.size());
for (int key : _intSet) { for (int key : _intSet) {
out.writeInt(key); out.writeInt(key);
@@ -69,7 +71,7 @@ public class IntSetStat extends Stat
public void unpersistFrom (ObjectInputStream in, AuxDataSource aux) public void unpersistFrom (ObjectInputStream in, AuxDataSource aux)
throws IOException, ClassNotFoundException throws IOException, ClassNotFoundException
{ {
_maxSize = in.readInt(); _maxSize = in.readByte() + 128;
int numValues = in.readInt(); int numValues = in.readInt();
_intSet = new HashSet<Integer>(numValues); _intSet = new HashSet<Integer>(numValues);
for (int ii = 0; ii < numValues; ii++) { for (int ii = 0; ii < numValues; ii++) {
@@ -87,4 +89,6 @@ public class IntSetStat extends Stat
protected int _maxSize; protected int _maxSize;
protected HashSet<Integer> _intSet = new HashSet<Integer>(); protected HashSet<Integer> _intSet = new HashSet<Integer>();
protected static final int MAX_MAX_SIZE = 255;
} }