1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.util;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.List;
22
23
24
25
26 public class AlphaIterator implements Serializable, Iterator {
27
28 private List<Inner> list = new ArrayList<Inner>();
29 private String prefix;
30
31 public AlphaIterator(String prefix){
32 super();
33 this.prefix = prefix;
34 }
35
36 @Override
37 public boolean hasNext() {
38 return true;
39 }
40
41 @Override
42 public Object next() {
43
44
45 if (list.isEmpty()) {
46 list.add(new Inner());
47 } else {
48
49
50 for (int i = list.size() - 1; i >= 0; i--) {
51 Inner in = list.get(i);
52 if (in.increment()>0) {
53 break;
54 } else {
55 in.reset();
56 if (i == 0) {
57 list.add(new Inner());
58 }
59 }
60 }
61 }
62
63
64 StringBuilder returnValue = new StringBuilder();
65 for (Inner in : list) {
66 returnValue.append((char)in.current());
67 }
68
69 return prefix + returnValue;
70 }
71
72 @Override
73 public void remove() {
74
75 }
76
77 private class Inner implements Serializable{
78
79 private final static int START = 'A';
80 private final static int END = 'Z';
81
82 private int value;
83
84 public Inner() {
85 value = START;
86 }
87
88 public void reset() {
89 value = START;
90 }
91
92 public int current() {
93 return value;
94 }
95
96 public int increment() {
97 if (value == END) {
98 return -1;
99 } else {
100 return value++;
101 }
102 }
103
104 }
105 }