View Javadoc

1   /*$Id: InMemoryNameGen.java,v 1.2 2005/04/25 12:13:30 clq2 Exp $
2    * Created on 18-Feb-2005
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
9    *
10  **/
11  package org.astrogrid.common.namegen;
12  
13  
14  import java.util.Random;
15  
16  /*** SImple name generator - returns a unique id based on time and random number.
17   * @author Noel Winstanley nw@jb.man.ac.uk 18-Feb-2005
18   *
19   */
20  public class InMemoryNameGen implements NameGen {
21  
22      /*** Construct a new InMemoryNameGen
23       * 
24       */
25      public InMemoryNameGen() {
26          super();
27      }
28  
29      /***
30       * Internal random number generator.
31       *  
32       */
33      private final Random random = new Random();
34  
35  
36      public synchronized String next() {
37          StringBuffer buffer = new StringBuffer();
38          buffer.append(Long.toHexString(System.currentTimeMillis())
39                  .toUpperCase());
40          buffer.append("-");
41          buffer.append(Integer.toHexString(random.nextInt()).toUpperCase());
42          return buffer.toString();
43      }
44  
45      public String toString() {
46          StringBuffer buffer = new StringBuffer();
47          buffer.append("[InMemoryNameGen:");
48          buffer.append("]");
49          return buffer.toString();
50      }
51  }
52  
53  
54  /* 
55  $Log: InMemoryNameGen.java,v $
56  Revision 1.2  2005/04/25 12:13:30  clq2
57  common-nww-1035
58  
59  Revision 1.1.2.1  2005/04/11 11:03:20  nw
60  moved name generator into common from filemanager - can then
61  reuse in jes too.
62  
63  Revision 1.2  2005/03/11 13:37:05  clq2
64  new filemanager merged with filemanager-nww-jdt-903-943
65  
66  Revision 1.1.2.1  2005/03/01 23:43:36  nw
67  split code inito client and server projoects again.
68  
69  Revision 1.1.2.2  2005/03/01 15:07:27  nw
70  close to finished now.
71  
72  Revision 1.1.2.1  2005/02/27 23:03:12  nw
73  first cut of talking to filestore
74  
75  Revision 1.1.2.1  2005/02/25 12:33:27  nw
76  finished transactional store
77   
78  */