At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel
------------------------------------------------------------
revno: 396
revision-id:mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: devel
timestamp: Wed 2007-12-26 20:47:27 -0600
message:
Copied in split method from connector/j to parameterize the generic types.
modified:
java/testsuite/BaseTestCase.java basetestcase.java-20070523000102-ggam3j202kmrm4es-5
=== modified file 'java/testsuite/BaseTestCase.java'
--- a/java/testsuite/BaseTestCase.java 2007-12-27 02:37:27 +0000
+++ b/java/testsuite/BaseTestCase.java 2007-12-27 02:47:27 +0000
@@ -16,6 +16,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Properties;
+import java.util.StringTokenizer;
import junit.framework.TestCase;
@@ -187,13 +188,13 @@
Properties props = new Properties();
if (propsList != null) {
- List<String> keyValuePairs = StringUtils.split(propsList, ",", false);
+ List<String> keyValuePairs = split(propsList, ",", false);
Iterator<String> iter = keyValuePairs.iterator();
while (iter.hasNext()) {
String kvp = iter.next();
- List<String> splitUp = StringUtils.split(kvp, "=", false);
+ List<String> splitUp = split(kvp, "=", false);
props.setProperty(splitUp.get(0).toString().trim(), splitUp.get(1).toString());
}
}
@@ -597,4 +598,102 @@
return buf.toString();
}
+
+ /**
+ * Splits stringToSplit into a list, using the given delimitter
+ *
+ * @param stringToSplit
+ * the string to split
+ * @param delimitter
+ * the string to split on
+ * @param trim
+ * should the split strings be whitespace trimmed?
+ *
+ * @return the list of strings, split by delimitter
+ *
+ * @throws IllegalArgumentException
+ * DOCUMENT ME!
+ */
+ public static final List<String> split(String stringToSplit, String delimitter,
+ boolean trim) {
+ if (stringToSplit == null) {
+ return new ArrayList<String>();
+ }
+
+ if (delimitter == null) {
+ throw new IllegalArgumentException();
+ }
+
+ StringTokenizer tokenizer = new StringTokenizer(stringToSplit,
+ delimitter, false);
+
+ List<String> splitTokens = new ArrayList<String>(tokenizer.countTokens());
+
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken();
+
+ if (trim) {
+ token = token.trim();
+ }
+
+ splitTokens.add(token);
+ }
+
+ return splitTokens;
+ }
+
+ /**
+ * Splits stringToSplit into a list, using the given delimitter
+ *
+ * @param stringToSplit
+ * the string to split
+ * @param delimitter
+ * the string to split on
+ * @param trim
+ * should the split strings be whitespace trimmed?
+ *
+ * @return the list of strings, split by delimiter
+ *
+ * @throws IllegalArgumentException
+ * DOCUMENT ME!
+ */
+ public static final List<String> split(String stringToSplit, String delimiter,
+ String markers, String markerCloses, boolean trim) {
+ if (stringToSplit == null) {
+ return new ArrayList<String>();
+ }
+
+ if (delimiter == null) {
+ throw new IllegalArgumentException();
+ }
+
+ int delimPos = 0;
+ int currentPos = 0;
+
+ List<String> splitTokens = new ArrayList<String>();
+
+ while ((delimPos = StringUtils.indexOfIgnoreCaseRespectMarker(currentPos,
+ stringToSplit, delimiter, markers, markerCloses, false)) != -1) {
+ String token = stringToSplit.substring(currentPos, delimPos);
+
+ if (trim) {
+ token = token.trim();
+ }
+
+ splitTokens.add(token);
+ currentPos = delimPos + 1;
+ }
+
+ if (currentPos < stringToSplit.length()) {
+ String token = stringToSplit.substring(currentPos);
+
+ if (trim) {
+ token = token.trim();
+ }
+
+ splitTokens.add(token);
+ }
+
+ return splitTokens;
+ }
}
| Thread |
|---|
| • Rev 396: Copied in split method from connector/j to parameterize the generic types. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/deve... | Monty Taylor | 27 Dec |