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