Find out the string which matches "regex" from "target", and sort the string with spacial order. The string elements are split by "split".
(String regex, String target, String split)
| 408 | * order. The string elements are split by "split". |
| 409 | */ |
| 410 | public static String sortString(String regex, String target, String split) { |
| 411 | Pattern p = Pattern.compile(regex); |
| 412 | Matcher matcher = p.matcher(target); |
| 413 | String original = null; |
| 414 | String replaceString = new String(); |
| 415 | |
| 416 | if (matcher.find()) { |
| 417 | original = matcher.group(1); |
| 418 | String[] out = original.split(split); |
| 419 | Collections.sort(Arrays.asList(out)); |
| 420 | for (int j = 0; j < out.length; j++) { |
| 421 | replaceString += (j > 0 ? ", " + out[j] : out[j]); |
| 422 | } |
| 423 | return target.replace(original, replaceString); |
| 424 | } |
| 425 | return target; |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Sort UDFs for golden plan |
no test coverage detected