Clover Coverage Report
Coverage timestamp: Thu Feb 13 2014 22:50:26 UTC
../../../../img/srcFileCovDistChart9.png 39% of files have more coverage
29   119   14   4.83
12   57   0.48   6
6     2.33  
1    
 
  Splitter       Line # 26 29 14 87.2% 0.87234044
 
  (28)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.base.utility;
17   
18    import java.util.Iterator;
19   
20   
21    /**
22    * Split given string into parts delimited by white space.
23    *
24    * @author Michael Meyling
25    */
 
26    public final class Splitter implements Iterator {
27   
28    /** Text to split. */
29    private final String text;
30   
31    /** Last found position. */
32    private int found;
33   
34    /** Start searching from here. */
35    private int start;
36   
37    /** Current found separator string. Consists of (perhaps several) delimiters. */
38    private String separator;
39   
40    /** Current found token. */
41    private String token;
42   
43    /**
44    * Constructor.
45    *
46    * @param text Text to split.
47    */
 
48  127 toggle public Splitter(final String text) {
49  127 this.text = text;
50  127 iterate();
51    }
52   
53    /**
54    * Split String by given delimiter.
55    * "a b c" is converted to "a", " ", "b", " ", "c".
56    * "a b c " is converted to "a", " ", "b", " ", "c", " ".
57    * "a b c" is converted to "a", " ", "b", " ", "c".
58    *
59    * @return Split text.
60    */
 
61  0 toggle public Object next() {
62  0 return nextToken();
63    }
64   
65    /**
66    * Qualified next method.
67    *
68    * @return Get next token.
69    */
 
70  322 toggle public String nextToken() {
71  322 if (token != null) {
72  205 final String result = token;
73  205 token = null;
74  205 return result;
75    }
76  117 if (separator != null) {
77  117 final String result = separator;
78  117 separator = null;
79  117 iterate();
80  117 return result;
81    }
82  0 return null;
83    }
84   
85    /**
86    * Iterate token and whitespace.
87    */
 
88  244 toggle private void iterate() {
89  244 found = start;
90  2271 while (found < text.length() && !Character.isWhitespace(text.charAt(found))) {
91  2027 found++;
92    }
93  244 if (found < text.length()) {
94  117 token = text.substring(start, found);
95  117 start = found;
96  299 while (found < text.length() && Character.isWhitespace(text.charAt(found))) {
97  182 found++;
98    }
99  117 separator = text.substring(start, found);
100  117 start = found;
101    } else {
102  127 separator = null;
103  127 token = text.substring(start);
104    }
105  244 if (token.length() == 0) {
106  39 token = null;
107    }
108    }
109   
 
110  449 toggle public boolean hasNext() {
111  449 return token != null || separator != null;
112    }
113   
114   
 
115  0 toggle public void remove() {
116  0 throw new UnsupportedOperationException("this iterator doesn't support this method");
117    }
118   
119    }