com.groupon.uuid
Class UUID

java.lang.Object
  extended by com.groupon.uuid.UUID

public final class UUID
extends Object

See README.md for more information


Field Summary
static byte[] MAC
           
static int PID
           
 
Constructor Summary
UUID()
          Constructor that generates a new UUID using the current process id, MAC address, and timestamp
UUID(byte[] bytes)
          Constructor that takes a byte array as this UUID's content
UUID(String id)
           
 
Method Summary
 boolean equals(Object o)
           
 byte[] getBytes()
          copy the content of this UUID, so that it can't be changed, and return it
 byte[] getMacFragment()
          extract MAC address fragment from raw UUID bytes, setting missing values to 0, thus the first 2 and a half bytes will be 0, followed by 3 and a half bytes of the active MAC address when the UUID was generated
 int getProcessId()
          extract process id from raw UUID bytes and return as int
 Date getTimestamp()
          extract timestamp from raw UUID bytes and return as int
 char getVersion()
          extract version field as a hex char from raw UUID bytes
 int hashCode()
           
 String toString()
           
static void useSequentialIds()
          Toggle uuid generator into sequential mode, so the random segment is in order and increases by one
static void useVariableIds()
          Toggle uuid generator into variable mode, so the random segment is in reverse order and increases by a large increment.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PID

public static final int PID

MAC

public static final byte[] MAC
Constructor Detail

UUID

public UUID()
Constructor that generates a new UUID using the current process id, MAC address, and timestamp


UUID

public UUID(byte[] bytes)
Constructor that takes a byte array as this UUID's content

Parameters:
bytes - UUID content

UUID

public UUID(String id)
Method Detail

useSequentialIds

public static void useSequentialIds()
Toggle uuid generator into sequential mode, so the random segment is in order and increases by one


useVariableIds

public static void useVariableIds()
Toggle uuid generator into variable mode, so the random segment is in reverse order and increases by a large increment. This is the default mode.


getBytes

public byte[] getBytes()
copy the content of this UUID, so that it can't be changed, and return it

Returns:
raw byte array of UUID

toString

public String toString()
Overrides:
toString in class Object

getVersion

public char getVersion()
extract version field as a hex char from raw UUID bytes

Returns:
version char

getProcessId

public int getProcessId()
extract process id from raw UUID bytes and return as int

Returns:
id of process that generated the UUID, or -1 for unrecognized format

getTimestamp

public Date getTimestamp()
extract timestamp from raw UUID bytes and return as int

Returns:
millisecond UTC timestamp from generation of the UUID, or null for unrecognized format

getMacFragment

public byte[] getMacFragment()
extract MAC address fragment from raw UUID bytes, setting missing values to 0, thus the first 2 and a half bytes will be 0, followed by 3 and a half bytes of the active MAC address when the UUID was generated

Returns:
byte array of UUID fragment, or null for unrecognized format

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2013. All Rights Reserved.