Click to See Complete Forum and Search --> : How to get currentPosition of a StringTokenizer object


Geir Arnesen
03-14-2000, 09:13 AM
I have an object instansiated from the StringTokenizer class. This class/object
has a privat property currentPosition. For my application I need to get hold
of this offsett telling where in the input string I am at a current stage
the parsing. How to I get access to the currentPosition???

rgds.

Geir A.

Tom Duffy
03-14-2000, 03:43 PM
Hello Geir:

Subclass StringTokenizer and add a public getter for currentPosition:

public class MyStringTokenizer extends java.util.StringTokenizer{

public MyStringTokenizer(s){
super(s);
}

public MyStringTokenizer(s, d){
super(s, d);
}

public MyStringTokenizer(s, d, b){
super(s, d, b);
}

public int getCurrentPosition(){
return this.currentPosition;
}
}

This class assumes that currentPosition is an int - which I don't know off
the top of my head. If it is not an int, then substitute the appropriate
data type in the method signature.

Hope this helps.

Tom Duffy

"Geir Arnesen" <geir.arnesen@aftenposten.no> wrote:
>
>I have an object instansiated from the StringTokenizer class. This class/object
>has a privat property currentPosition. For my application I need to get
hold
>of this offsett telling where in the input string I am at a current stage
>the parsing. How to I get access to the currentPosition???
>
>rgds.
>
>Geir A.

Geir Arnesen
03-15-2000, 03:38 AM
Sorry, - but this gives me upon compile time "Error: (21) variable currentPosition
has private access in class java.util.StringTokenizer.

Any better clues??

Rgds.
Geir A.

"Tom Duffy" <td4729@hotmail.com> wrote:
>
>Hello Geir:
>
>Subclass StringTokenizer and add a public getter for currentPosition:
>
>public class MyStringTokenizer extends java.util.StringTokenizer{
>
>public MyStringTokenizer(s){
>super(s);
>}
>
>public MyStringTokenizer(s, d){
>super(s, d);
>}
>
>public MyStringTokenizer(s, d, b){
>super(s, d, b);
>}
>
>public int getCurrentPosition(){
>return this.currentPosition;
>}
>}
>
>This class assumes that currentPosition is an int - which I don't know off
>the top of my head. If it is not an int, then substitute the appropriate
>data type in the method signature.
>
>Hope this helps.
>
>Tom Duffy
>
>"Geir Arnesen" <geir.arnesen@aftenposten.no> wrote:
>>
>>I have an object instansiated from the StringTokenizer class. This class/object
>>has a privat property currentPosition. For my application I need to get
>hold
>>of this offsett telling where in the input string I am at a current stage
>>the parsing. How to I get access to the currentPosition???
>>
>>rgds.
>>
>>Geir A.
>