Example usage for java.util UUID timestamp

List of usage examples for java.util UUID timestamp

Introduction

In this page you can find the example usage for java.util UUID timestamp.

Prototype

public long timestamp() 

Source Link

Document

The timestamp value associated with this UUID.

Usage

From source file:Main.java

public static void main(String[] args) {
    // creating UUID      
    UUID uid = UUID.randomUUID();

    // checking time stamp value
    System.out.println("Time stamp value: " + uid.timestamp());
}

From source file:Main.java

public static long getTimestamp(String uuid) {
    UUID uu = UUID.fromString(uuid);
    return uu.timestamp();
}

From source file:net.geertvos.theater.core.util.UUIDGen.java

/**
 * Returns a milliseconds-since-epoch value for a type-1 UUID.
 * // ww  w. j  a  v a  2s  . c om
 * @param uuid a type-1 (time-based) UUID
 * @return the number of milliseconds since the unix epoch
 * @throws IllegalArgumentException if the UUID is not version 1
 */
public static long getAdjustedTimestamp(UUID uuid) {
    if (uuid.version() != 1)
        throw new IllegalArgumentException("incompatible with uuid version: " + uuid.version());
    return (uuid.timestamp() / 10000) - START_EPOCH;
}

From source file:com.easemob.dataexport.utils.UUIDUtils.java

public static long getTimestampInMillis(UUID uuid) {
    if (uuid == null) {
        return 0;
    }/* ww  w  . j  av a 2  s.  co m*/
    long t = uuid.timestamp();
    return (t - KCLOCK_OFFSET) / KCLOCK_MULTIPLIER_L;
}

From source file:com.easemob.dataexport.utils.UUIDUtils.java

public static long getTimestampInMicros(UUID uuid) {
    if (uuid == null) {
        return 0;
    }/*from  w ww  .ja  va2s.  com*/
    long t = uuid.timestamp();
    return (t - KCLOCK_OFFSET) / 10;
}

From source file:org.usergrid.utils.UUIDUtils.java

public static long getTimestampInMillis(UUID uuid) {
    if (uuid == null) {
        return 0;
    }//  w  w w . j  a va  2s  .c  o m
    long t = uuid.timestamp();
    long timeMillis = (t - kClockOffset) / kClockMultiplierL;
    return timeMillis;
}

From source file:org.usergrid.utils.UUIDUtils.java

public static long getTimestampInMicros(UUID uuid) {
    if (uuid == null) {
        return 0;
    }// w  ww.  j a  v  a 2 s.  c o  m
    long t = uuid.timestamp();
    long timeMillis = (t - kClockOffset) / 10;
    return timeMillis;
}

From source file:com.easemob.dataexport.utils.UUIDUtils.java

/** Returns a UUID that is -1 of the passed uuid, sorted by time uuid only */
public static UUID decrement(UUID uuid) {
    if (!isTimeBased(uuid)) {
        throw new IllegalArgumentException("The uuid must be a time type");
    }/*from   w  w  w.  j a  v a  2s .co  m*/

    //timestamp is in the 60 bit timestamp
    long timestamp = uuid.timestamp();
    timestamp--;

    if (timestamp < 0) {
        throw new IllegalArgumentException("You must specify a time uuid with a timestamp > 0");
    }

    //get our bytes, then set the smaller timestamp into it
    byte[] uuidBytes = bytes(uuid);

    setTime(uuidBytes, timestamp);

    return uuid(uuidBytes);
}

From source file:org.logger.event.cassandra.loader.CassandraDataLoader.java

public static long getTimeFromUUID(UUID uuid) {
    return (uuid.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH) / 10000;
}

From source file:net.sourceforge.vulcan.spring.SpringFileStore.java

public synchronized Map<String, List<UUID>> getBuildOutcomeIDs() {
    final Map<String, List<UUID>> map = new HashMap<String, List<UUID>>();
    final File[] projects = getProjectsRoot().listFiles();

    if (projects == null) {
        throw new IllegalStateException("cannot list contents of " + getProjectsRoot());
    }/*from   ww w  .ja va 2s  . co m*/

    for (File f : projects) {
        final List<UUID> list = new ArrayList<UUID>();

        final String[] ids = new File(f, "outcomes").list();
        if (ids == null) {
            continue;
        }

        for (String id : ids) {
            list.add(UUID.fromString(id));
        }

        // Sort in chronological order
        Collections.sort(list, new Comparator<UUID>() {
            @Override
            public int compare(UUID o1, UUID o2) {
                final long t1 = o1.timestamp();
                final long t2 = o2.timestamp();

                if (t1 > t2) {
                    return 1;
                } else if (t1 < t2) {
                    return -1;
                }
                return 0;
            }
        });
        map.put(f.getName(), list);
    }
    return map;
}