1 16 package web.rss; 17 18 import java.io.Serializable ; 19 import java.security.MessageDigest ; 20 import java.security.NoSuchAlgorithmException ; 21 22 import dlog4j.util.StringUtils; 23 24 28 public class Item implements Serializable { 29 30 protected String title; 31 protected String link; 32 protected String description; 33 34 public Item() { 35 } 36 37 public String getDescription() { 38 return description; 39 } 40 public void setDescription(String description) { 41 this.description = description; 42 } 43 public String getLink() { 44 return link; 45 } 46 public void setLink(String link) { 47 this.link = link; 48 } 49 public String getTitle() { 50 return title; 51 } 52 public void setTitle(String title) { 53 this.title = title; 54 } 55 56 public String uuid() { 57 try{ 58 MessageDigest md = MessageDigest.getInstance("SHA-1"); 59 if(title!=null) 60 md.update(title.getBytes()); 61 if(link!=null) 62 md.update(link.getBytes()); 63 if(description!=null) 64 md.update(description.getBytes()); 65 byte[] bs = md.digest(); 66 return StringUtils.byte2hex(bs); 67 }catch(NoSuchAlgorithmException e){} 68 return null; 69 } 70 71 public int hashCode() { 72 return uuid().hashCode(); 73 } 74 75 public static void main(String [] args){ 76 Item itm = new Item(); 77 itm.setTitle("Java自由人"); 78 itm.setLink("http://www.javayou.com/main.jspe"); 79 itm.setDescription("Java自由人 Bloging..."); 80 System.out.println(itm.uuid()); 81 } 82 } 83 | Popular Tags |