]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils/src/org/simantics/utils/UniqueID.java
Changing existing log4j logging to use slf4j
[simantics/platform.git] / bundles / org.simantics.utils / src / org / simantics / utils / UniqueID.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.utils;\r
13 \r
14 import java.util.Random;\r
15 \r
16 /**\r
17  * UniqueID attempts to creates unique IDs. \r
18  * @author Toni Kalajainen\r
19  * @deprecated should be removed in my opinion [Tuukka], no real use.\r
20  */\r
21 public class UniqueID {\r
22     \r
23     public static final String RESTORE_PREFIX = "restore-";\r
24     \r
25     protected final static Random RANDOM = new Random(System.currentTimeMillis());\r
26     protected static long COUNTER = RANDOM.nextLong();\r
27     \r
28     public static String _createUniqueID() {\r
29         synchronized(UniqueID.class) {\r
30             Long value = COUNTER++;\r
31             Long random = RANDOM.nextLong();\r
32             return Long.toHexString(value).toUpperCase() + \r
33                    Long.toHexString(random);\r
34         }\r
35     }    \r
36 \r
37     public static String createViewSiteSecondaryID(boolean restore) {\r
38         if (!restore)\r
39             return _createUniqueID();\r
40         return RESTORE_PREFIX+_createUniqueID();\r
41     }\r
42        \r
43     \r
44 }\r