Move the CRC computation to its own method so that we can use it elsewhere.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@1088 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Andrzej Kapolka
2011-05-10 03:46:16 +00:00
parent 5750084ad2
commit 59a3e8bcaf
@@ -87,9 +87,7 @@ public abstract class Stat
public static int initType (Type type, Stat prototype)
{
// compute a code for this stat using the CRC32 hash of its name
_crc.reset();
_crc.update(type.name().getBytes());
int code = (int)_crc.getValue();
int code = crc32(type.name());
// make sure the code does not collide
if (_codeToType.containsKey(code)) {
@@ -106,6 +104,16 @@ public abstract class Stat
return code;
}
/**
* Computes and returns the CRC32 hash of the specified string.
*/
public static int crc32 (String string)
{
_crc.reset();
_crc.update(string.getBytes());
return (int)_crc.getValue();
}
/**
* Returns the type of this statistic.
*/