View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.tokenizer;
12  
13  import java.io.IOException;
14  import java.io.StringReader;
15  
16  import org.slf4j.Logger;
17  import org.slf4j.LoggerFactory;
18  
19  /**
20   * The Class StringTokenizer.
21   */
22  public class StringTokenizer extends Tokenizer {
23  
24    /** The Constant logger. */
25    private static final Logger logger = LoggerFactory.getLogger(StringTokenizer.class);
26  
27    /**
28     * Instantiates a new string tokenizer.
29     */
30    public StringTokenizer() {
31      // Required due to override
32    }
33  
34    /**
35     * Instantiates a new string tokenizer.
36     *
37     * @param str the str
38     */
39    public StringTokenizer(final String str) {
40      setString(str);
41    }
42  
43    /**
44     * Sets the string.
45     *
46     * @param str the new string
47     */
48    public void setString(final String str) {
49      setReader(new StringReader(str));
50    }
51  
52    @Override
53    public boolean hasMore() {
54      try {
55        return super.hasMore();
56      } catch (IOException e) {
57        logger.trace("", e);
58        return false;
59      }
60    }
61  
62    @Override
63    public Token getToken() {
64      try {
65        return super.getToken();
66      } catch (IOException e) {
67        logger.trace("", e);
68        return null;
69      }
70    }
71  
72    @Override
73    public Token nextToken() {
74      try {
75        return super.nextToken();
76      } catch (IOException e) {
77        logger.trace("", e);
78        return null;
79      }
80    }
81  
82  }