37 |
|
|
38 |
package javax.swing.text; |
package javax.swing.text; |
39 |
|
|
40 |
public class Segment implements Cloneable, CharacterIterator |
import java.text.CharacterIterator; |
41 |
|
|
42 |
|
|
43 |
|
public class Segment |
44 |
|
implements Cloneable, CharacterIterator |
45 |
{ |
{ |
46 |
char[] array; |
public char[] array; |
47 |
int count; |
public int count; |
48 |
int offset; |
public int offset; |
49 |
|
|
50 |
|
public Segment() |
51 |
|
{ |
52 |
|
} |
53 |
|
|
54 |
|
public Segment(char[] array, int offset, int count) |
55 |
|
{ |
56 |
|
this.array = array; |
57 |
|
this.offset = offset; |
58 |
|
this.count = count; |
59 |
|
} |
60 |
|
|
61 |
public Object clone() |
public Object clone() |
62 |
{ |
{ |
63 |
try { |
try |
64 |
|
{ |
65 |
return super.clone(); |
return super.clone(); |
|
} catch (Exception e) { |
|
|
System.err.println("Huuuhhh, this class implements cloneable !!!!!!"); |
|
|
System.err.println("I think there is a bug in this JVM somewhere"); |
|
66 |
} |
} |
67 |
|
catch (CloneNotSupportedException e) |
68 |
|
{ |
69 |
return null; |
return null; |
70 |
} |
} |
71 |
|
} |
72 |
|
|
73 |
public char current() |
public char current() |
74 |
{ |
{ |
90 |
{ |
{ |
91 |
return offset + count; |
return offset + count; |
92 |
} |
} |
93 |
|
|
94 |
public int getIndex() |
public int getIndex() |
95 |
{ |
{ |
96 |
return offset; |
return offset; |
97 |
} |
} |
98 |
|
|
99 |
public char last() |
public char last() |
100 |
{ |
{ |
101 |
offset = getEndIndex() - 1; |
offset = getEndIndex() - 1; |
102 |
return array[offset]; |
return array[offset]; |
103 |
} |
} |
104 |
|
|
105 |
public char next() |
public char next() |
106 |
{ |
{ |
107 |
offset++; |
offset++; |
108 |
return array[offset]; |
return array[offset]; |
109 |
} |
} |
110 |
|
|
111 |
public char previous() |
public char previous() |
112 |
{ |
{ |
113 |
offset--; |
offset--; |
114 |
return array[offset]; |
return array[offset]; |
115 |
} |
} |
116 |
|
|
117 |
public char setIndex(int position) |
public char setIndex(int position) |
118 |
{ |
{ |
119 |
offset = position; |
offset = position; |
125 |
return new String(array, offset, count); |
return new String(array, offset, count); |
126 |
} |
} |
127 |
} |
} |
|
|
|