blob: 4242a87d65b8097f9f12766281c95c8869285484 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/*
* Copyright (c) 2010-2015 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
/*
* Copyright (c) 2015 Tarun Gupta.
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
package com.isode.stroke.base;
import com.isode.stroke.base.IDGenerator;
/**
* @brief The SimpleIDGenerator class implements a IDGenerator generating consecutive ID strings from
* the lower case latin alphabet.
*/
public class SimpleIDGenerator extends IDGenerator {
private static String currentID;
/**
* Constructor
*/
public SimpleIDGenerator() {
currentID = "";
}
/**
* Simply generates a UUID.
* @return a String which will never be null or empty.
*/
public static String generateID() {
boolean carry = true;
int i = 0;
char[] char_currentID = currentID.toCharArray();
while (carry && i < char_currentID.length) {
char c = char_currentID[i];
if (c >= 'z') {
char_currentID[i] = 'a';
}
else {
char_currentID[i] = (char)(c+1);
carry = false;
}
++i;
}
currentID = String.valueOf(char_currentID);
if (carry) {
currentID += 'a';
}
return currentID;
}
}
|