1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt.io.id;
18
19 import org.apache.commons.betwixt.io.IDGenerator;
20
21 /*** <p>Abstract superclass for {@link IDGenerator} implementations.</p>
22 *
23 * <p>It implements the entire <code>IDGenerator</code> interface.
24 * When <code>nextId</code> is called,
25 * this class sets the <code>LastId</code> property (as well
26 * as returning the value).
27 * Subclasses should override {@link #nextIdImpl}.</p>
28 *
29 * @author <a href="mailto:rdonkin@apache.org">Robert Burrell Donkin</a>
30 * @version $Revision: 438373 $
31 */
32 public abstract class AbstractIDGenerator implements IDGenerator {
33
34 /*** Last <code>ID</code> returned */
35 private String lastId = "0";
36
37 /***
38 * Gets last <code>ID</code> returned.
39 *
40 * @return the last id created by the generated
41 */
42 public final String getLastId() {
43 return lastId;
44 }
45
46 /***
47 * <p>Generate next <code>ID</code>.</p>
48 *
49 * <p>This method obtains the next <code>ID</code> from subclass
50 * and then uses this to set the <code>LastId</code> property.</p>
51 *
52 * @return the next id generated
53 */
54 public final String nextId() {
55 lastId = nextIdImpl();
56 return lastId;
57 }
58
59 /***
60 * Subclasses should <strong>provide an implementation</strong> for this method.
61 * This implementation needs only provide the next <code>ID</code>
62 * value (according to it's algorithm).
63 * Setting the <code>LastId</code> property can be left to this class.
64 *
65 * @return the next id generated
66 */
67 protected abstract String nextIdImpl();
68 }