me.prettyprint.cassandra.utils
Class TimeUUIDUtils

java.lang.Object
  extended by me.prettyprint.cassandra.utils.TimeUUIDUtils

public final class TimeUUIDUtils
extends Object

Utilitary class to generate TimeUUID (type 1)

Author:
Patricio Echague (pechague@gmail.com)

Constructor Summary
TimeUUIDUtils()
           
 
Method Summary
static byte[] asByteArray(UUID uuid)
          As byte array.
static ByteBuffer asByteBuffer(UUID uuid)
          Coverts a java.util.UUID into a ByteBuffer.
static long getTimeFromUUID(byte[] uuid)
          Retrieves the time as long based on the byte[] representation of a UUID.
static long getTimeFromUUID(UUID uuid)
           
static UUID getTimeUUID(ClockResolution clock)
          Gets a new time uuid using ClockResolution.createClock() as a time generator.
static UUID getTimeUUID(long time)
          Gets a new time uuid based on time.
static UUID getUniqueTimeUUIDinMillis()
          Gets a new and unique time uuid in milliseconds.
static UUID toUUID(byte[] uuid)
          Returns an instance of uuid.
static UUID uuid(byte[] uuid, int offset)
           
static UUID uuid(ByteBuffer bb)
          Converts a ByteBuffer containing a UUID into a java.util.UUID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeUUIDUtils

public TimeUUIDUtils()
Method Detail

getUniqueTimeUUIDinMillis

public static UUID getUniqueTimeUUIDinMillis()
Gets a new and unique time uuid in milliseconds. It is useful to use in a TimeUUIDType sorted column family.

Returns:
the time uuid

getTimeUUID

public static UUID getTimeUUID(ClockResolution clock)
Gets a new time uuid using ClockResolution.createClock() as a time generator. It is useful to use in a TimeUUIDType sorted column family.

Parameters:
clock - a ClockResolution
Returns:
the time uuid

getTimeUUID

public static UUID getTimeUUID(long time)
Gets a new time uuid based on time. NOTE: this algorithm does not resolve duplicates. To avoid duplicates use getTimeUUID(ClockResolution clock) with an implementaion that provides unique timestamp resolution, like MicrosecondsSyncClockResolution It is useful to use in a TimeUUIDType sorted column family.

Parameters:
clock - a ClockResolution
Returns:
the time uuid

toUUID

public static UUID toUUID(byte[] uuid)
Returns an instance of uuid. Useful for when you read out of cassandra you are getting a byte[] that needs to be converted into a TimeUUID.

Parameters:
uuid - the uuid
Returns:
the java.util.uuid

getTimeFromUUID

public static long getTimeFromUUID(byte[] uuid)
Retrieves the time as long based on the byte[] representation of a UUID.

Parameters:
uuid - byte[] uuid representation
Returns:
a long representing the time

getTimeFromUUID

public static long getTimeFromUUID(UUID uuid)

asByteArray

public static byte[] asByteArray(UUID uuid)
As byte array. This method is often used in conjunction with @link #getTimeUUID()

Parameters:
uuid - the uuid
Returns:
the byte[]

asByteBuffer

public static ByteBuffer asByteBuffer(UUID uuid)
Coverts a java.util.UUID into a ByteBuffer.

Parameters:
uuid - a java.util.UUID
Returns:
a ByteBuffer representaion of the param UUID

uuid

public static UUID uuid(byte[] uuid,
                        int offset)

uuid

public static UUID uuid(ByteBuffer bb)
Converts a ByteBuffer containing a UUID into a java.util.UUID

Parameters:
bb - a ByteBuffer containing a UUID
Returns:
a java.util.UUID


Copyright © 2011. All Rights Reserved.