001 package org.kuali.rice.krms.util;
002
003 import java.io.Serializable;
004 import java.util.ArrayList;
005 import java.util.Iterator;
006 import java.util.List;
007
008 /**
009 * Created with IntelliJ IDEA.
010 * User: SW
011 * Date: 2013/02/12
012 * Time: 12:15 PM
013 * To change this template use File | Settings | File Templates.
014 */
015 public class AlphaIterator implements Serializable, Iterator {
016
017 private List<Inner> list = new ArrayList<Inner>();
018
019 @Override
020 public boolean hasNext() {
021 return true;
022 }
023
024 @Override
025 public Object next() {
026
027 //Add an initial value to the list
028 if (list.isEmpty()) {
029 list.add(new Inner());
030 } else {
031
032 //Increment the value
033 for (int i = list.size() - 1; i >= 0; i--) {
034 Inner in = list.get(i);
035 if (in.increment()>0) {
036 break;
037 } else {
038 in.reset();
039 if (i == 0) {
040 list.add(new Inner());
041 }
042 }
043 }
044 }
045
046 //Create the return string
047 String returnValue = "";
048 for (Inner in : list) {
049 returnValue = returnValue + (char)in.current();
050 }
051
052 return returnValue;
053 }
054
055 @Override
056 public void remove() {
057 //To change body of implemented methods use File | Settings | File Templates.
058 }
059
060 private class Inner {
061
062 private final static int START = 'A';
063 private final static int END = 'Z';
064
065 private int value;
066
067 public Inner() {
068 value = START;
069 }
070
071 public void reset() {
072 value = START;
073 }
074
075 public int current() {
076 return value;
077 }
078
079 public int increment() {
080 if (value == END) {
081 return -1;
082 } else {
083 return value++;
084 }
085 }
086
087 }
088 }