Android ID Generate generateId(Object... value)

Here you can find the source of generateId(Object... value)

Description

generate Id

License

Apache License

Declaration

public static long generateId(Object... value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.security.MessageDigest;

public class Main {
    private static final Object sLock = new Object();
    private static MessageDigest md;

    public static long generateId(Object... value) {
        if (md == null) {
            return 0L;
        }//from  w w  w .  jav  a2 s  . c  o m
        //String value to be converted
        StringBuilder builder = new StringBuilder();
        for (Object s : value) {
            builder.append(String.valueOf(s));
        }
        byte[] hashValBytes;
        synchronized (sLock) {
            md.reset();
            //convert the string value to a byte array and pass it into the hash algorithm
            md.update(builder.toString().getBytes());

            //retrieve a byte array containing the digest
            hashValBytes = md.digest();
        }

        long hashValLong = 0;

        //create a long value from the byte array
        for (int i = 0; i < 8; i++) {
            hashValLong |= ((long) (hashValBytes[i]) & 0x0FF) << (8 * i);
        }
        return hashValLong;
    }
}

Related

  1. generateSyncEventId()
  2. getSequenceId()
  3. generateId(Object... value)
  4. generateRecordingIdentifier()
  5. getAndroidId(Context context)
  6. generateKey()
  7. generateRandomUIID()