View Javadoc
1   /******************************************************************************
2    * SetsCRC.java - Calculate a CRC of the Sets
3    * 
4    * PicManService - The BuckoSoft Picture Manager in Java
5    * Copyright(c) 2008 - Dick Balaska
6    * 
7    */
8   package com.buckosoft.PicMan.util;
9   
10  import com.buckosoft.PicMan.domain.Set;
11  
12  /** Calculate a CRC of the Sets.
13   * This is used between the client and service to determine if sets have changed and need sync.
14   * @author Dick Balaska
15   * @since 2008/11/11
16   * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicManService/src/com/buckosoft/PicMan/util/SetsCRC.java">SetsCRC.java</a>
17   */
18  public class SetsCRC {
19  
20  	private	long	crc = 0;
21  	
22  	public long getCRC() {
23  		return(crc);
24  	}
25  
26  	public void addSet(Set set) {
27  		int x = 1;
28  		int i;
29  		for (i=0; i<set.getName().length(); i++) {
30  			int c = set.getName().charAt(i);
31  			crc += c*x;
32  			if (x++ > 5)
33  				x = 1;
34  		}
35  		for (i=0; i<set.getDescription().length(); i++) {
36  			int c = set.getDescription().charAt(i);
37  			crc += c*x;
38  			if (x++ > 5)
39  				x = 1;
40  		}
41  		if (set.isMetaSet())
42  			crc += x;
43  		x++;
44  		if (set.isMicroSet() || set.isNanoSet())
45  			crc += x;
46  		x++;
47  		
48  	}
49  }