01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2007 Robert Grimm
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public License
07: * version 2.1 as published by the Free Software Foundation.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.util;
20:
21: /**
22: * A nonce.
23: *
24: * @author Robert Grimm
25: * @version $Revision: 1.2 $
26: */
27: public class Nonce {
28:
29: /** The number. */
30: private final long number;
31:
32: /**
33: * Create a new nonce.
34: *
35: * @param number The number.
36: */
37: private Nonce(long number) {
38: this .number = number;
39: }
40:
41: /**
42: * Get this nonce's number.
43: *
44: * @return The number.
45: */
46: public long getNumber() {
47: return number;
48: }
49:
50: public String toString() {
51: return "nonce(" + number + ')';
52: }
53:
54: // ========================================================================
55:
56: /** The current count. */
57: private static long count = 0;
58:
59: /**
60: * Create a new nonce.
61: *
62: * @return The new nonce.
63: */
64: public static Nonce create() {
65: Nonce n = new Nonce(count++);
66: if (0 == count)
67: throw new AssertionError("Out of nonces");
68: return n;
69: }
70:
71: }
|