1 18 19 20 21 package sync4j.syncclient.spds.util; 22 23 24 25 36 37 public class StrParser { 38 39 40 41 43 44 45 private int position; 46 47 48 49 private String str = null; 50 51 private String parserDelim = null; 52 53 54 55 56 57 59 60 61 72 73 public StrParser(String str, String parserDelim) { 74 75 76 77 position = 0; 78 79 80 81 this.str = str; 82 83 this.parserDelim = parserDelim; 84 85 86 87 } 88 89 90 91 93 94 95 106 107 public boolean hasMoreElements() { 108 109 110 111 126 127 128 129 131 if (str.substring(position).indexOf(parserDelim) != -1 132 133 || str.substring(position).length() > 0) { 134 135 return true; 136 137 } else { 138 139 return false; 140 141 } 142 143 144 145 } 146 147 148 149 150 151 156 157 public String nextElement() { 158 159 160 161 int positionOld; 162 163 int positionTmp; 164 165 166 167 positionOld = position; 168 169 170 171 positionTmp = str.substring(position).indexOf(parserDelim); 172 173 174 175 176 177 if (positionTmp != -1) { 178 179 position = position + positionTmp + parserDelim.length(); 180 181 return str.substring(positionOld, position - parserDelim.length()); 182 183 } else { 184 185 position = str.length(); 186 187 return str.substring(positionOld, position); 188 189 } 190 191 192 193 } 194 195 196 197 198 199 204 205 public int countElements() { 206 207 208 209 int count = 0; 210 211 int index = 0; 212 213 214 215 String strTmp = null; 216 217 218 219 strTmp = str; 220 221 222 223 while (strTmp != null && strTmp.length() > 0) { 224 225 count++; 226 227 228 229 index = strTmp.indexOf(parserDelim); 230 231 232 233 if (index == -1) 234 235 break; 236 237 238 239 strTmp = strTmp.substring(index + 1); 240 241 } 242 243 244 245 return count; 246 247 } 248 249 } | Popular Tags |