Android Utililty Methods Hash Code Calculate

List of utility methods to do Hash Code Calculate

Description

The list of methods to do Hash Code Calculate are organized into topic(s).

Method

StringgetHashStringFromId(String id)
Create Hash (string) value from id string by using SHA-256 hash algorithm Return null if id is null or functionality is not supported by JVM
if (id == null)
    return null;
try {
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    md.update(id.getBytes("UTF-8"));
    byte[] digest = md.digest();
    return bytesToHex(digest);
} catch (NoSuchAlgorithmException e) {
...
intgetHexDigit(String s, int i)
get Hex Digit
char c = s.charAt(i);
if (c >= '0' && c <= '9') {
    return c - '0';
} else if (c >= 'a' && c <= 'f') {
    return c - 'a' + 0xa;
} else if (c >= 'A' && c <= 'F') {
    return c - 'A' + 0xa;
} else {
...
intcreateHash(String title, String URL, String content)
create Hash
int hash = 1;
hash = hash * 31 + (title == null ? 0 : title.hashCode());
hash = hash * 31 + (URL == null ? 0 : URL.hashCode());
hash = hash * 31 + (content == null ? 0 : content.hashCode());
return hash;
StringcreateHash(String toHash)
create Hash
String mResult = null;
try {
    MessageDigest mDigest = MessageDigest
            .getInstance(HASH_ALGORITHM);
    mDigest.reset();
    mDigest.update(toHash.getBytes());
    byte[] mBytes = mDigest.digest();
    int mLength = mBytes.length;
...
inthash(int aSeed, boolean aBoolean)
Hash code for boolean primitives.
return firstTerm(aSeed) + (aBoolean ? 1 : 0);
inthash(int aSeed, char aChar)
Hash code for char primitives.
return firstTerm(aSeed) + aChar;
inthash(int aSeed, int aInt)
Hash code for int primitives.
return firstTerm(aSeed) + aInt;
inthash(int aSeed, long aLong)
Hash code for long primitives.
return firstTerm(aSeed) + (int) (aLong ^ (aLong >>> 32));
inthash(int aSeed, float aFloat)
Hash code for float primitives.
return hash(aSeed, Float.floatToIntBits(aFloat));
inthash(int aSeed, double aDouble)
Hash code for double primitives.
return hash(aSeed, Double.doubleToLongBits(aDouble));