1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
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 }