Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
29   132   11   7.25
16   50   0.48   4
4     3.5  
1    
 
 
  EscapedStringTokenizer       Line # 62 29 11 98% 0.97959185
 
No Tests
 
1    /*
2    * EscapedStringTokenizer.java
3    *
4    * Created on 2006/12/16, 5:41pm
5    *
6    * Copyright (c) 2006, University of Kent
7    * All rights reserved.
8    *
9    * Redistribution and use in source and binary forms, with or without
10    * modification, are permitted provided that the following conditions are met:
11    *
12    * Redistributions of source code must retain the above copyright notice, this
13    * list of conditions and the following disclaimer.
14    *
15    * Redistributions in binary form must reproduce the above copyright notice,
16    * this list of conditions and the following disclaimer in the documentation
17    * and/or other materials provided with the distribution.
18    *
19    * 1. Neither the name of the University of Kent nor the names of its
20    * contributors may be used to endorse or promote products derived from this
21    * software without specific prior written permission.
22    *
23    * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26    * PURPOSE ARE DISCLAIMED.
27    *
28    * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35    * POSSIBILITY OF SUCH DAMAGE.
36    *
37    * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
38    * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
39    * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
40    * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
41    * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
42    * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
43    * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
44    * SERIOUS FAULTS, IN THIS SOFTWARE.
45    *
46    * 5. This license is governed, except to the extent that local laws
47    * necessarily apply, by the laws of England and Wales.
48    *
49    * Author : Gansen Zhao
50    * Email: gz7@kent.ac.uk
51    *
52    */
53   
54    package issrg.pba.rbac.xmlpolicy;
55   
56    import java.util.Enumeration;
57   
58    /**
59    *
60    * @author gansen
61    */
 
62    public class EscapedStringTokenizer implements Enumeration{
63   
64    String m_str;
65    char m_delim;
66    int m_curpos;
67    /** Creates a new instance of EscapedStringTokenizer */
 
68  181 toggle public EscapedStringTokenizer(String strTobeSplit, char delim) {
69  181 m_str=strTobeSplit;
70  181 m_delim=delim;
71  181 m_curpos=0;
72    }
73   
 
74  575 toggle private int nextDelimPosition(){
75   
76   
77  575 boolean bIsOddAppearance=false;
78  575 boolean bNonDelim=false;
79   
80    //check from current position to find the next delim.
81  3903 for(int i=m_curpos;i<m_str.length();i++)
82  3360 if(m_str.charAt(i)==m_delim){
83  46 bIsOddAppearance=!bIsOddAppearance;
84  3314 }else if(bIsOddAppearance==true){
85    // we have found a odd number of delims, and its's also the end of the delim sequences
86    //thus the current position is the end.
87  32 return i;
88    }
89  543 return m_str.length();
90    }
91   
 
92  378 toggle public boolean hasMoreElements() {
93   
94  378 int i =0;
95  378 i = this.nextDelimPosition();
96  378 if(i>this.m_curpos)
97  197 return true;
98  181 return false;
99    }
100   
 
101  197 toggle public Object nextElement() {
102   
103  197 Object obj=null;
104  197 boolean bIsOddAppearance=false;
105   
106  197 int next = this.nextDelimPosition();
107   
108  197 String nextE="";
109   
110  1861 for(int i = this.m_curpos; i<next; i++){
111  1664 if(m_str.charAt(i)!=m_delim)
112  1641 if((this.m_curpos>0)&&(i == this.m_curpos)&&(m_str.charAt(i)==' ')){//if the first charactor is white space
113    //do nothing here
114    }else{//otherwise
115  1641 nextE=nextE+m_str.charAt(i);
116    }
117    else{
118  23 bIsOddAppearance=!bIsOddAppearance;
119  23 if(bIsOddAppearance==false)
120  2 nextE=nextE+m_str.charAt(i);
121    }
122    }
123   
124   
125  197 this.m_curpos=next;
126  197 return obj=nextE;
127   
128    }
129   
130   
131   
132    }