import java.text.*;

// Cannot subclass the final class StringCharacterIterator
public class ProcessingStringCharacterIterator implements CharacterIterator
{
	private String text;
	private int index;
	
	public ProcessingStringCharacterIterator(String text)
	{
		this.text=text;
		reset();			
	}
	
	public void reset()
	{
		index=0;
	}

	protected char charAt(int position)
	{
		if (0<=position && position<text.length())
			return text.charAt(position);
		return DONE;			
	}

	public char current()
	{
		return charAt(index);
	}
	
	public char first()
	{
		index=0;
		return current();
	}
	
	public int getBeginIndex()
	{
		return 0;
	}
	
	public int getEndIndex()
	{
		return text.length();
	}
	
	public int getIndex()
	{
		return index;
	}
	
	public char last()
	{
		index=getEndIndex()-1;
		return current();
	}
	
	public char next()
	{
		index++;
		return charAt(index);
	}
	
	public char previous()
	{
		index--;
		return charAt(index);
	}
		
	public char setIndex(int position) throws IllegalArgumentException
	{
		if (0<=position && position<text.length())
			index=position;
		return charAt(position);
	}
		
	public Object clone()
	{
		ProcessingStringCharacterIterator copy=new ProcessingStringCharacterIterator(text);
		copy.setIndex(index);			
		return copy;
	}
		
	public void process()
	{
	}
	
	public void process(Processable processable)
	{
		for (char c=first();c!=CharacterIterator.DONE;c=next())
			processable.process(c);
	}
}
