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