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