From 59a3e8bcaff0616df83e8fa2f177f423be91adef Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 10 May 2011 03:46:16 +0000 Subject: [PATCH] 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 --- src/main/java/com/threerings/stats/data/Stat.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/threerings/stats/data/Stat.java b/src/main/java/com/threerings/stats/data/Stat.java index 61f97a57..b60ef6f1 100644 --- a/src/main/java/com/threerings/stats/data/Stat.java +++ b/src/main/java/com/threerings/stats/data/Stat.java @@ -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. */