Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../img/srcFileCovDistChart9.png 45% 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
 
  (51)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, 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  217912 toggle public Splitter(final String text) {
49  217912 this.text = text;
50  217912 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  809831 toggle public String nextToken() {
71  809831 if (token != null) {
72  480885 final String result = token;
73  480885 token = null;
74  480885 return result;
75    }
76  328946 if (separator != null) {
77  328946 final String result = separator;
78  328946 separator = null;
79  328946 iterate();
80  328946 return result;
81    }
82  0 return null;
83    }
84   
85    /**
86    * Iterate token and whitespace.
87    */
 
88  546858 toggle private void iterate() {
89  546858 found = start;
90  3927573 while (found < text.length() && !Character.isWhitespace(text.charAt(found))) {
91  3380715 found++;
92    }
93  546858 if (found < text.length()) {
94  328946 token = text.substring(start, found);
95  328946 start = found;
96  763526 while (found < text.length() && Character.isWhitespace(text.charAt(found))) {
97  434580 found++;
98    }
99  328946 separator = text.substring(start, found);
100  328946 start = found;
101    } else {
102  217912 separator = null;
103  217912 token = text.substring(start);
104    }
105  546858 if (token.length() == 0) {
106  65973 token = null;
107    }
108    }
109   
 
110  1027743 toggle public boolean hasNext() {
111  1027743 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    }