Skip to content

Commit

Permalink
[HWKMETRICS-241] remove uuid lib dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
John Sanda committed Sep 1, 2015
1 parent 780823c commit 3c149b6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 65 deletions.
6 changes: 0 additions & 6 deletions core/metrics-core-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@
<artifactId>commons-math3</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>

<groupId>com.github.stephenc.eaio-uuid</groupId>
<artifactId>uuid</artifactId>
<version>3.4.0</version>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,13 @@

import org.joda.time.DateTime;

import com.datastax.driver.core.utils.UUIDs;
import com.eaio.uuid.UUIDGen;

/**
* @author John Sanda
*/
public class TimeUUIDUtils {

static final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L;

// This function is taken from the Hector library.
//
// The MIT License
//
// Copyright (c) 2010 Ran Tavory
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
public static UUID getTimeUUID(long time) {
return new UUID(createTime(time), UUIDGen.getClockSeqAndNode());
}

private static long createTime(long currentTime) {
long time;

// UTC time
long timeToUse = (currentTime * 10000) + NUM_100NS_INTERVALS_SINCE_UUID_EPOCH;

// time low
time = timeToUse << 32;

// time mid
time |= (timeToUse & 0xFFFF00000000L) >> 16;

// time hi and version
time |= 0x1000 | ((timeToUse >> 48) & 0x0FFF); // version 1
return time;
return UUIDGen.getTimeUUID(time);
}

public static UUID getTimeUUID(Date d) {
Expand All @@ -83,17 +38,4 @@ public static UUID getTimeUUID(DateTime d) {
return getTimeUUID(d.getMillis());
}

public static int compare(UUID u1, UUID u2) {
long ts1 = UUIDs.unixTimestamp(u1);
long ts2 = UUIDs.unixTimestamp(u2);

if (ts1 > ts2) {
return 1;
}
if (ts1 < ts2) {
return -1;
}
return u1.compareTo(u2);
}

}

0 comments on commit 3c149b6

Please sign in to comment.