1 package org.openphacts.nextprot.util;
2
3 /**
4 * <code>HashTool</code> provides hashing functions inside a velocity context.
5 *
6 * Created: Wed Jun 13 17:59:01 2012
7 *
8 * @author <a href="mailto:">Oliver Karch</a>
9 * @version 1.0
10 */
11 import java.math.BigDecimal;
12 import java.util.zip.Adler32;
13
14 import org.apache.velocity.tools.generic.SafeConfig;
15
16 public class HashTool extends SafeConfig {
17
18 /**
19 * Creates a new HashTool.
20 */
21 public HashTool() {
22 super();
23 } // HashTool constructor
24
25 /**
26 * Creates an Adler23 checksum from the given content.
27 *
28 * @param obj the object for which the crc is calculated.
29 * @return a number object representing the string content of the object.
30 */
31 public Number adler( Object obj ) {
32 Adler32 nn = new Adler32();
33 nn.update( obj.toString().getBytes() );
34 return new BigDecimal(nn.getValue());
35 }
36
37 } // HashTool