Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UUID |
|
| 1.0;1 |
1 | /* | |
2 | * Copyright (c) 2003-2008, by Henrik Arro and Contributors | |
3 | * | |
4 | * This file is part of JSeq, a tool to automatically create | |
5 | * sequence diagrams by tracing program execution. | |
6 | * | |
7 | * See <http://jseq.sourceforge.net> for more information. | |
8 | * | |
9 | * JSeq is free software: you can redistribute it and/or modify | |
10 | * it under the terms of the GNU Lesser General Public License as | |
11 | * published by the Free Software Foundation, either version 3 of | |
12 | * the License, or (at your option) any later version. | |
13 | * | |
14 | * JSeq is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU Lesser General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU Lesser General Public License | |
20 | * along with JSeq. If not, see <http://www.gnu.org/licenses/>. | |
21 | */ | |
22 | ||
23 | package th.co.edge.jseq.argouml; | |
24 | ||
25 | import java.net.InetAddress; | |
26 | import java.net.UnknownHostException; | |
27 | import java.rmi.server.UID; | |
28 | ||
29 | /** | |
30 | * A <code>UUID</code> is a utility class that is used to generate "globally" | |
31 | * unique identifiers. | |
32 | * | |
33 | * <p> | |
34 | * The algorithm uses the IP address of the machine running the code as part of | |
35 | * the identifier, so an external address needs to be available to make the | |
36 | * numbers really unique. | |
37 | */ | |
38 | public class UUID { | |
39 | 1 | private static String address = ""; |
40 | ||
41 | /** | |
42 | * Since this is a utility class containing only static methods, we hide the | |
43 | * only constructor. | |
44 | */ | |
45 | 0 | private UUID() { |
46 | 0 | } |
47 | ||
48 | static { | |
49 | try { | |
50 | 1 | InetAddress inetAddress = InetAddress.getLocalHost(); |
51 | 1 | byte[] bytes = inetAddress.getAddress(); |
52 | 1 | StringBuffer sb = new StringBuffer(); |
53 | 5 | for (int i = 0; i < bytes.length; i++) { |
54 | 4 | Byte b = new Byte(bytes[i]); |
55 | 4 | sb.append(b.longValue() + "-"); |
56 | } | |
57 | 1 | address = sb.toString(); |
58 | 0 | } catch (UnknownHostException e) { |
59 | 0 | System.err.println(e); |
60 | 1 | } |
61 | 1 | } |
62 | ||
63 | /** | |
64 | * Returns a globally unique identifier. | |
65 | * | |
66 | * @return a globally unique identifier | |
67 | */ | |
68 | public static String getID() { | |
69 | 53 | UID uid = new UID(); |
70 | 53 | return address + uid; |
71 | } | |
72 | } |