01: /*
02: * Copyright 2006 Davide Deidda
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: /*
18: * Created on 29-nov-2003
19: *
20: * Sequencer.java
21: * copyright(C) BioBytes 2003
22: */
23: package it.biobytes.ammentos.util;
24:
25: import java.util.*;
26:
27: /**
28: * Sequence generator.
29: *
30: * @author Davide Deidda
31: */
32: public class Sequencer {
33: private static long m_counter; // Static counter
34: private static long m_seed;
35:
36: static {
37: m_seed = new Date().getTime();
38: m_counter = 0;
39: }
40:
41: /**
42: * Generates a new long value
43: *
44: * @return
45: */
46: public synchronized static long nextLong() {
47: return (m_seed + m_counter++);
48: }
49:
50: public synchronized static int nextInt() {
51: return (int) nextLong();
52: }
53:
54: public synchronized static short nextShort() {
55: return (short) nextLong();
56: }
57:
58: public static synchronized String nextString() {
59: return Long.toHexString(nextLong());
60: }
61:
62: }
|