private static List<?> parseStringToList(String string) { Matcher candidate = Coerce.listPattern.matcher(string); if (!Coerce.listBracketsMatch(candidate)) { return Collections.<Object>emptyList(); } List<String> list = Lists.newArrayList(); for (String part : candidate.group(2).split(",")) { if (part != null) { list.add(part); } } return list; }
/** * Sanitise a string containing a common representation of a number to make * it parsable. Strips thousand-separating commas and trims later members * of a comma-separated list. For example the string "(9.5, 10.6, 33.2)" * will be sanitised to "9.5". * * @param obj Object to sanitise * @return Sanitised number-format string to parse */ private static String sanitiseNumber(Object obj) { String string = obj.toString().trim(); if (string.length() < 1) { return "0"; } Matcher candidate = Coerce.listPattern.matcher(string); if (Coerce.listBracketsMatch(candidate)) { string = candidate.group(2).trim(); } int decimal = string.indexOf('.'); int comma = string.indexOf(',', decimal); if (decimal > -1 && comma > -1) { return Coerce.sanitiseNumber(string.substring(0, comma)); } if (string.indexOf('-', 1) != -1) { return "0"; } return string.replace(",", "").split(" ")[0]; }
if (listBracketsMatch(vecMatch)) { return new Vector2i(Integer.parseInt(vecMatch.group(1)), Integer.parseInt(vecMatch.group(2)));
private static List<?> parseStringToList(String string) { Matcher candidate = Coerce.listPattern.matcher(string); if (!Coerce.listBracketsMatch(candidate)) { return Collections.<Object>emptyList(); } List<String> list = Lists.newArrayList(); for (String part : candidate.group(2).split(",")) { if (part != null) { list.add(part); } } return list; }
/** * Sanitise a string containing a common representation of a number to make * it parseable. Strips thousand-separating commas and trims later members * of a comma-separated list. For example the string "(9.5, 10.6, 33.2)" * will be sanitised to "9.5". * * @param obj Object to sanitise * @return Sanitised number-format string to parse */ private static String sanitiseNumber(Object obj) { String string = obj.toString().trim(); if (string.length() < 1) { return "0"; } Matcher candidate = Coerce.listPattern.matcher(string); if (Coerce.listBracketsMatch(candidate)) { string = candidate.group(2).trim(); } int decimal = string.indexOf('.'); int comma = string.indexOf(',', decimal); if (decimal > -1 && comma > -1) { return Coerce.sanitiseNumber(string.substring(0, comma)); } if (string.indexOf('-', 1) != -1) { return "0"; } return string.replace(",", "").split(" ")[0]; }
if (listBracketsMatch(vecMatch)) { return new Vector2i(Integer.parseInt(vecMatch.group(1)), Integer.parseInt(vecMatch.group(2)));