use of java.util.StringTokenizer in project groovy-core by groovy.
the class StringGroovyMethods method split.
/**
* Convenience method to split a CharSequence (with whitespace as delimiter).
* Similar to tokenize, but returns an Array of String instead of a List.
*
* @param self the CharSequence to split
* @return String[] result of split
* @see #split(String)
* @since 1.8.2
*/
public static String[] split(CharSequence self) {
StringTokenizer st = new StringTokenizer(self.toString());
String[] strings = new String[st.countTokens()];
for (int i = 0; i < strings.length; i++) {
strings[i] = st.nextToken();
}
return strings;
}
use of java.util.StringTokenizer in project j2objc by google.
the class StringTokenizerTest method test_nextTokenLjava_lang_String.
/**
* @tests java.util.StringTokenizer#nextToken(java.lang.String)
*/
public void test_nextTokenLjava_lang_String() {
// Test for method java.lang.String
// java.util.StringTokenizer.nextToken(java.lang.String)
StringTokenizer st = new StringTokenizer("This is a test String");
assertEquals("nextToken(String) returned incorrect value with normal token String", "This", st.nextToken(" "));
assertEquals("nextToken(String) returned incorrect value with custom token String", " is a ", st.nextToken("tr"));
assertEquals("calling nextToken() did not use the new default delimiter list", "es", st.nextToken());
}
use of java.util.StringTokenizer in project j2objc by google.
the class StringTokenizerTest method test_nextToken_NPE.
public void test_nextToken_NPE() {
StringTokenizer stringTokenizer = new StringTokenizer(new String(), (String) null, true);
try {
stringTokenizer.nextToken();
fail("should throw NullPointerException");
} catch (NullPointerException e) {
// Expected
}
stringTokenizer = new StringTokenizer(new String(), (String) null);
try {
stringTokenizer.nextToken();
fail("should throw NullPointerException");
} catch (NullPointerException e) {
// Expected
}
}
use of java.util.StringTokenizer in project j2objc by google.
the class FuncId method getNodesByID.
/**
* Fill in a list with nodes that match a space delimited list if ID
* ID references.
*
* @param xctxt The runtime XPath context.
* @param docContext The document where the nodes are being looked for.
* @param refval A space delimited list of ID references.
* @param usedrefs List of references for which nodes were found.
* @param nodeSet Node set where the nodes will be added to.
* @param mayBeMore true if there is another set of nodes to be looked for.
*
* @return The usedrefs value.
*/
private StringVector getNodesByID(XPathContext xctxt, int docContext, String refval, StringVector usedrefs, NodeSetDTM nodeSet, boolean mayBeMore) {
if (null != refval) {
String ref = null;
// DOMHelper dh = xctxt.getDOMHelper();
StringTokenizer tokenizer = new StringTokenizer(refval);
boolean hasMore = tokenizer.hasMoreTokens();
DTM dtm = xctxt.getDTM(docContext);
while (hasMore) {
ref = tokenizer.nextToken();
hasMore = tokenizer.hasMoreTokens();
if ((null != usedrefs) && usedrefs.contains(ref)) {
ref = null;
continue;
}
int node = dtm.getElementById(ref);
if (DTM.NULL != node)
nodeSet.addNodeInDocOrder(node, xctxt);
if ((null != ref) && (hasMore || mayBeMore)) {
if (null == usedrefs)
usedrefs = new StringVector();
usedrefs.addElement(ref);
}
}
}
return usedrefs;
}
use of java.util.StringTokenizer in project groovy-core by groovy.
the class Groovyc method extractJointOptions.
private List<String> extractJointOptions(Path classpath) {
List<String> jointOptions = new ArrayList<String>();
if (!jointCompilation)
return jointOptions;
// extract joint options, some get pushed up...
RuntimeConfigurable rc = javac.getRuntimeConfigurableWrapper();
for (Object o1 : rc.getAttributeMap().entrySet()) {
final Map.Entry e = (Map.Entry) o1;
final String key = e.getKey().toString();
final String value = getProject().replaceProperties(e.getValue().toString());
if (key.contains("debug")) {
String level = "";
if (javac.getDebugLevel() != null) {
level = ":" + javac.getDebugLevel();
}
jointOptions.add("-Fg" + level);
} else if (key.contains("debugLevel")) {
// ignore, taken care of in debug
} else if ((key.contains("nowarn")) || (key.contains("verbose")) || (key.contains("deprecation"))) {
// false is default, so something to do only in true case
if ("on".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value))
jointOptions.add("-F" + key);
} else if (key.contains("classpath")) {
classpath.add(javac.getClasspath());
} else if ((key.contains("depend")) || (key.contains("extdirs")) || (key.contains("encoding")) || (key.contains("source")) || (key.contains("target")) || (key.contains("verbose"))) {
// already handling verbose but pass on too
jointOptions.add("-J" + key + "=" + value);
} else {
log.warn("The option " + key + " cannot be set on the contained <javac> element. The option will be ignored");
}
// TODO includes? excludes?
}
// ant's <javac> supports nested <compilerarg value=""> elements (there can be multiple of them)
// for additional options to be passed to javac.
Enumeration children = rc.getChildren();
while (children.hasMoreElements()) {
RuntimeConfigurable childrc = (RuntimeConfigurable) children.nextElement();
if (childrc.getElementTag().equals("compilerarg")) {
for (Object o : childrc.getAttributeMap().entrySet()) {
final Map.Entry e = (Map.Entry) o;
final String key = e.getKey().toString();
if (key.equals("value")) {
final String value = getProject().replaceProperties(e.getValue().toString());
StringTokenizer st = new StringTokenizer(value, " ");
while (st.hasMoreTokens()) {
String optionStr = st.nextToken();
String replaced = optionStr.replace("-X", "-FX");
if (optionStr.equals(replaced)) {
// GROOVY-5063
replaced = optionStr.replace("-W", "-FW");
}
jointOptions.add(replaced);
}
}
}
}
}
return jointOptions;
}
Aggregations