1 18 19 package sync4j.syncclient.sps.common.util; 20 21 22 28 public class StrParser { 29 30 32 private int position; 33 34 private String str = null; 35 private String parserDelim = null; 36 37 39 45 public StrParser(String str, String parserDelim) { 46 47 position = 0; 48 49 this.str = str; 50 51 this.parserDelim = parserDelim; 52 53 } 54 55 57 63 64 public boolean hasMoreElements() { 65 66 83 84 if (str.substring(position).indexOf(parserDelim) != -1 88 89 || str.substring(position).length() > 0) { 90 91 return true; 92 93 } else { 94 95 return false; 96 97 } 98 99 } 100 101 102 105 public String nextElement() { 106 107 int positionOld; 108 109 int positionTmp; 110 111 positionOld = position; 112 113 positionTmp = str.substring(position).indexOf(parserDelim); 114 115 if (positionTmp != -1) { 116 117 position = position + positionTmp + parserDelim.length(); 118 119 return str.substring(positionOld, position - parserDelim.length()); 120 121 } else { 122 123 position = str.length(); 124 125 return str.substring(positionOld, position); 126 127 } 128 129 } 130 131 132 135 public int countElements() { 136 137 int count = 0; 138 int index = 0; 139 140 String strTmp = null; 141 142 strTmp = str; 143 144 while (strTmp != null && strTmp.length() > 0) { 145 146 count++; 147 148 index = strTmp.indexOf(parserDelim); 149 150 if (index == -1) { 151 break; 152 } 153 154 strTmp = strTmp.substring(index + 1); 155 156 } 157 158 return count; 159 160 } 161 162 } | Popular Tags |