Home | History | Annotate | Download | only in signature
      1 package com.bumptech.glide.signature;
      2 
      3 import com.bumptech.glide.load.Key;
      4 
      5 import java.io.UnsupportedEncodingException;
      6 import java.security.MessageDigest;
      7 
      8 /**
      9  * A unique Signature that wraps a String.
     10  */
     11 public class StringSignature implements Key {
     12     private final String signature;
     13 
     14     public StringSignature(String signature) {
     15         if (signature == null) {
     16             throw new NullPointerException("Signature cannot be null!");
     17         }
     18         this.signature = signature;
     19     }
     20 
     21     @Override
     22     public boolean equals(Object o) {
     23         if (this == o) {
     24             return true;
     25         }
     26         if (o == null || getClass() != o.getClass()) {
     27             return false;
     28         }
     29 
     30         StringSignature that = (StringSignature) o;
     31 
     32         return signature.equals(that.signature);
     33     }
     34 
     35     @Override
     36     public int hashCode() {
     37         return signature.hashCode();
     38     }
     39 
     40     @Override
     41     public void updateDiskCacheKey(MessageDigest messageDigest) throws UnsupportedEncodingException {
     42         messageDigest.update(signature.getBytes(STRING_CHARSET_NAME));
     43     }
     44 }
     45