View Javadoc

1   /*
2    * Created on Jan 24, 2004
3    *
4    * To change the template for this generated file go to
5    * Window>Preferences>Java>Code Generation>Code and Comments
6    */
7   package com.sharkysoft.printf;
8   
9   import java.text.CharacterIterator;
10  import java.text.StringCharacterIterator;
11  
12  /***
13   * @author sharky
14   *
15   * To change the template for this generated type comment go to
16   * Window>Preferences>Java>Code Generation>Code and Comments
17   */
18  final class PrintfStringCharacterIterator implements CharacterIterator
19  {
20  	private final CharacterIterator mpCi;
21  	
22  	PrintfStringCharacterIterator(final CharacterIterator ipCi)
23  	{
24  		mpCi = ipCi;
25  	}
26  	
27  	private final StringBuffer mpBuff = new StringBuffer();
28  	 
29  	private boolean mzCurrentAppended = false;
30  
31  	private void forget()
32  	{
33  		mpBuff.setLength(0);
34  		mzCurrentAppended = false;
35  	}
36    public char current()
37    {
38      char vcC = mpCi.current();
39      if (! mzCurrentAppended)
40      {
41      	mpBuff.append(vcC);
42      	mzCurrentAppended = true;
43      }
44      return vcC;
45    }
46  
47  	String getSubstring()
48  	{
49  		return mpBuff.toString();
50  	}
51  	
52    public boolean equals(Object obj)
53    {
54      return mpCi.equals(obj);
55    }
56  
57    public char first()
58    {
59    	forget();
60      return mpCi.first();
61    }
62  
63    public int getBeginIndex()
64    {
65      return mpCi.getBeginIndex();
66    }
67  
68    public int getEndIndex()
69    {
70      return mpCi.getEndIndex();
71    }
72  
73    public int getIndex()
74    {
75      return mpCi.getIndex();
76    }
77  
78    public int hashCode()
79    {
80      return mpCi.hashCode();
81    }
82  
83    public char last()
84    {
85  		forget();
86      return mpCi.last();
87    }
88  
89    public char next()
90    {
91    	if (mzCurrentAppended)
92    		mzCurrentAppended = false;
93    	else
94    		mpBuff.append(mpCi.current());
95      return mpCi.next();
96    }
97  
98    public char previous()
99    {
100 		forget();
101     return mpCi.previous();
102   }
103 
104   public char setIndex(int position)
105   {
106 		forget();
107     return mpCi.setIndex(position);
108   }
109 
110   public String toString()
111   {
112     return mpCi.toString();
113   }
114 
115   public Object clone() 
116   {
117     return new PrintfStringCharacterIterator((StringCharacterIterator) mpCi.clone());
118   }
119 
120 }
121