added:
#isTimestampUUID
#timestamp
#version
comment/format in:
#deepCopy
#deepCopyUsing:postCopySelector:
#shallowCopy
#simpleDeepCopy
changed:
#genRandomUUID
#genTimestampUUID
#node
--- a/UUID.st Fri Apr 20 17:17:19 2012 +0200
+++ b/UUID.st Fri Apr 20 17:18:41 2012 +0200
@@ -373,7 +373,15 @@
!
node
- ^ self copyFrom:11 to:16
+ "answer the node (ethernet) address of this uuid"
+
+ ^ (ByteArray new:6) replaceFrom:1 to:6 with:self startingAt:11.
+
+ "
+ (self allInstances
+ select:[:e| e isTimestampUUID]
+ thenCollect:[:e| e node]) asBag
+ "
!
timeHighAndVersion
@@ -386,6 +394,39 @@
timeMid
^ self unsignedShortAt:5 bigEndian:true
+!
+
+timestamp
+ "Get the UTC timestamp, when the UUID has been created.
+ This is only valid for timestampUUIDs"
+
+ |low med high dtssUtcTime|
+
+ low := self unsignedLongAt:1 bigEndian:true.
+ med := self unsignedShortAt:5 bigEndian:true.
+ high := (self unsignedShortAt:7 bigEndian:true) bitAnd:16rFFF.
+
+ dtssUtcTime := low + ((med + (high bitShift:16)) bitShift:32).
+
+ ^ Timestamp utcMillisecondsSince1970:(dtssUtcTime//10000)-12219292800000.
+
+ "
+ self genTimestampUUID timestamp
+
+ (self allInstances asSet asArray select:[:e| e isTimestampUUID]
+ thenCollect:[:e| e timestamp]) sort
+ "
+!
+
+version
+ "the version number of the uuid"
+
+ ^ ((self at:7) bitAnd:16rF0) bitShift:-4.
+
+ "
+ self genTimestampUUID version
+ self genRandomUUID version
+ "
! !
!UUID methodsFor:'converting'!
@@ -452,18 +493,30 @@
!UUID methodsFor:'copying'!
deepCopy
+ "I am never changed, after I have been created.
+ So there is no need to make a copy"
+
^ self
!
deepCopyUsing:aDictionary postCopySelector:postCopySelector
+ "I am never changed, after I have been created.
+ So there is no need to make a copy"
+
^ self
!
shallowCopy
+ "I am never changed, after I have been created.
+ So there is no need to make a copy"
+
^ self
!
simpleDeepCopy
+ "I am never changed, after I have been created.
+ So there is no need to make a copy"
+
^ self
! !
@@ -472,6 +525,11 @@
genRandomUUID
"answer a randomly generated uuid as defined in RFC4122 section 4.4"
+ (self at:7) ~~ 0 ifTrue:[
+ "once created, an UUID is immutable"
+ self noModificationError.
+ ].
+
self replaceFrom:1 to:16 with:(RandomGenerator new nextBytes:16).
"multiplex the 4 bit version number (Version 4 -> Random UUID) in high bits of byte 7"
self at:7 put:(((self at:7) bitAnd:16r0F) bitOr:16r40).
@@ -479,6 +537,8 @@
"
self new genRandomUUID
+
+ self genRandomUUID genRandomUUID
"
"
@@ -511,6 +571,11 @@
self error:'no mac address - cannot generate UUID'.
].
+ (self at:7) ~~ 0 ifTrue:[
+ "once created, an UUID is immutable"
+ self noModificationError.
+ ].
+
"use 60 bit counter of 100ns ticks since 00:00:00 15.oct 1582 (sigh)"
utcTime := self class getDtssUtcTime.
@@ -558,6 +623,7 @@
"
self new genTimestampUUID
+ self genTimestampUUID genTimestampUUID
"
"
@@ -705,14 +771,20 @@
"
! !
+!UUID methodsFor:'queries'!
+
+isTimestampUUID
+ ^ self version == 1
+! !
+
!UUID class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/UUID.st,v 1.36 2011-12-26 12:43:06 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/UUID.st,v 1.37 2012-04-20 15:18:41 stefan Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic2/UUID.st,v 1.36 2011-12-26 12:43:06 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/UUID.st,v 1.37 2012-04-20 15:18:41 stefan Exp $'
! !
UUID initialize!