KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Util > DFSRChecker > parser > StringTokenizer


1 /*
2  * $Id: StringTokenizer.java,v 1.4 2005/07/08 12:04:12 kofron Exp $
3  *
4  * Copyright 2004
5  * Distributed Systems Research Group
6  * Department of Software Engineering
7  * Faculty of Mathematics and Physics
8  * Charles University, Prague
9  *
10  * Copyright 2005
11  * Formal Methods In Software Engineering Group
12  * Institute of Computer Science
13  * Academy of Sciences of the Czech Republic
14  *
15  * This code was developed by Jan Kofron <kofron@nenya.ms.mff.cuni.cz>
16  */

17
18 package SOFA.SOFAnode.Util.DFSRChecker.parser;
19
20 import java.io.IOException JavaDoc;
21
22 /**
23  * This class it to replace the originally used StringReader in order to be able
24  * to provide information about the index in the string where the current token
25  * lies.
26  *
27  */

28 public class StringTokenizer extends ProtocolReader {
29
30     /**
31      * Creates a new instance of StringTokenizer.
32      * @param source the source string to be read.
33      */

34     public StringTokenizer(String JavaDoc source) {
35         this.source = source;
36     }
37
38     /**
39      * Reads the next character
40      *
41      * @return the character read
42      */

43     public int read() {
44         if (index == source.length())
45             return -1;
46         else
47             return source.charAt(index++);
48     }
49
50     /**
51      * Checks whether the source string is not yet parsed completelly
52      *
53      * @return true if there are character left, false otherwise
54      */

55     public boolean ready() {
56         return source.length() >= index;
57     }
58
59     /**
60      * @return the index within the string being parsed
61      *
62      */

63     public int getIndex() {
64         return index;
65     }
66
67     /**
68      * @see java.io.Reader#close()
69      */

70     public void close() throws IOException JavaDoc {
71         //nothing to be done
72
}
73
74     /**
75      * @see java.io.Reader#read(char[], int, int)
76      */

77     public int read(char[] cbuf, int off, int len) throws IOException JavaDoc {
78         //not implemented
79
throw new IOException JavaDoc("Not implemented");
80     }
81
82     /**
83      * @see SOFA.SOFAnode.Util.objectweb.fractal.behprotocols.checker.parser.ProtocolReader#resetIndex()
84      */

85     public void resetIndex() {
86         // makes nothing
87
}
88     //-----------------------------------------------------------------------------------
89

90     /**
91      * The string being parsed
92      */

93     private String JavaDoc source;
94
95     /**
96      * The current index within the string being parsed
97      */

98     int index = 0;
99
100
101
102 }
Popular Tags