Mercurial > hg > blitz_stable
comparison src/org/dancres/util/Timestamp.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.util; | |
2 | |
3 import java.util.HashMap; | |
4 | |
5 /** | |
6 Generates timestamps values which can be used to uniquely order events. | |
7 */ | |
8 public class Timestamp { | |
9 private static HashMap theTimestamps = new HashMap(); | |
10 | |
11 public static Timestamp newTimestamp(String aName) { | |
12 synchronized(theTimestamps) { | |
13 if (theTimestamps.get(aName) != null) | |
14 throw new IllegalArgumentException("Timestamp already exists"); | |
15 | |
16 Timestamp myTimestamp = new Timestamp(); | |
17 theTimestamps.put(aName, myTimestamp); | |
18 | |
19 return myTimestamp; | |
20 } | |
21 } | |
22 | |
23 public static Timestamp getTimestamp(String aName) { | |
24 synchronized(theTimestamps) { | |
25 return (Timestamp) theTimestamps.get(aName); | |
26 } | |
27 } | |
28 | |
29 long theStamp = 0; | |
30 | |
31 private Timestamp() { | |
32 } | |
33 | |
34 /** | |
35 Returns the last timestamp allocated or zero if none have been | |
36 allocated yet. | |
37 */ | |
38 public long get() { | |
39 synchronized(this) { | |
40 return theStamp; | |
41 } | |
42 } | |
43 | |
44 /** | |
45 Return the next timestamp | |
46 */ | |
47 public long next() { | |
48 synchronized(this) { | |
49 return ++theStamp; | |
50 } | |
51 } | |
52 } |