View Javadoc
1 package jsdsi; 2 3 import java.util.Iterator; 4 5 import jsdsi.sexp.Sexp; 6 import jsdsi.sexp.SexpList; 7 import jsdsi.sexp.SexpParseException; 8 import jsdsi.sexp.SexpUtil; 9 10 /*** 11 * The cryptographic hash of an object. 12 * 13 * @author Sameer Ajmani 14 * @author Sean Radford 15 * @version $Revision: 1.4.2.1 $ $Date: 2005/11/08 03:12:52 $ 16 */ 17 public class ObjectHash extends Obj implements Subject { 18 19 private static final long serialVersionUID = 5513858723159477992L; 20 21 /*** 22 * The <code>Hash</code> of this <code>ObjectHash</code>. 23 */ 24 private transient final Hash hash; 25 26 /*** 27 * The <code>Hash</code> of this <code>ObjectHash</code>. 28 */ 29 public ObjectHash(Hash h) { 30 assert(h != null) : "null hash"; 31 hash = h; 32 } 33 34 /*** 35 * @return the <code>Hash</code> of this <code>ObjectHash</code>. 36 */ 37 public Hash getHash() { 38 return hash; 39 } 40 41 /*** 42 * Checks whether this <code>ObjectHash</code> is a hash of the given 43 * object. 44 * 45 * @param o object to check for if this object hash is a hash from it. 46 * @return <code>true</code> if this object hash is a hash of 47 * <code>o</code>, <code>false</code> otherwise. 48 */ 49 public boolean isHashOf(Obj o) { 50 Hash h = new Hash(hash.getDigest(), o, hash.getURIs()); 51 return hash.equals(h); 52 } 53 54 /*** 55 * @see java.lang.Object#equals(Object) 56 */ 57 public boolean equals(Object o) { 58 return (o instanceof ObjectHash) && hash.equals(((ObjectHash) o).hash); 59 } 60 61 /*** 62 * @see java.lang.Object#hashCode() 63 */ 64 public int hashCode() { 65 return hash.hashCode(); 66 } 67 68 /*** 69 * Returns an S-expression of this <code>ObjectHash</code> 70 */ 71 public SexpList toSexp() { 72 Sexp[] ss = new Sexp[1]; 73 ss[0] = getHash().toSexp(); 74 return SexpUtil.toSexp("object-hash", ss); 75 } 76 77 /*** 78 * Creates a new <code>ObjectHash</code> of an 79 * <code>SexpList</code>. 80 * 81 * @param l the <code>SexpList</code> that holds the 82 * <code>ObjectHash</code>. 83 * @return the <code>ObjectHash</code> that is created. 84 * @throws SexpParseException 85 */ 86 static ObjectHash parseObjectHash(SexpList l) throws SexpParseException { 87 Iterator obody = SexpUtil.getBody(l); 88 Hash hash = Hash.parseHash(SexpUtil.getNextList(obody, "object hash")); 89 SexpUtil.checkDone(obody, "object-hash"); 90 return new ObjectHash(hash); 91 } 92 }

This page was automatically generated by Maven