MCPcopy Create free account
hub / github.com/GateNLP/gate-core / toSet

Method toSet

src/main/java/gate/util/Strings.java:256–281  ·  view source on GitHub ↗

Get back a Set of String from its String representation. Unescape backslashed separator characters. @param string String to convert to a List @param separator String that delimits the element of the set @return a linked hashset @see #toString(java.util.LinkedHashSet)

(String string, String separator)

Source from the content-addressed store, hash-verified

254 * @see #toString(java.util.LinkedHashSet)
255 */
256 public static LinkedHashSet<String> toSet(String string, String separator) {
257 LinkedHashSet<String> set = new LinkedHashSet<String>();
258 if (string == null
259 || string.length() < 3) {
260 return set;
261 }
262 // remove last character
263 String value = string.substring(0, string.length()-1);
264 int index = 1;
265 int startIndex = 1;
266 int separatorIndex;
267 // split on element separator
268 while ((separatorIndex = value.indexOf(separator, index)) != -1) {
269 // check that the separator is not an escaped character
270 if (value.charAt(separatorIndex-1) != '\\') {
271 set.add(value.substring(startIndex, separatorIndex)
272 // unescape separator
273 .replaceAll("\\\\"+separator.charAt(0), ""+separator.charAt(0)));
274 startIndex = separatorIndex + separator.length();
275 }
276 index = separatorIndex + separator.length();
277 }
278 // last element of the set
279 set.add(value.substring(startIndex));
280 return set;
281 }
282
283 /**
284 * Get back a Map of String*String from its String representation.

Callers 2

toMapMethod · 0.95
getSetMethod · 0.95

Calls 4

charAtMethod · 0.80
indexOfMethod · 0.65
addMethod · 0.65
lengthMethod · 0.45

Tested by

no test coverage detected