Here you can find the source of splitTypeArguments(final String nestedTypes)
Parameter | Description |
---|---|
nestedTypes | a parameter |
private static String[] splitTypeArguments(final String nestedTypes)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { /**// w ww . ja va 2s . c o m * Splits the provided string of nested types into separate top-level * instances. * * @param nestedTypes * * @return */ private static String[] splitTypeArguments(final String nestedTypes) { StringBuilder string = new StringBuilder(nestedTypes.replaceAll("\\s*", "")); List<String> arguments = new ArrayList<String>(); while (string.length() > 0) { int nextComma = string.indexOf(","); int nextOpen = string.indexOf("<"); if (nextComma == -1) { arguments.add(string.toString()); string.setLength(0); } else if (nextOpen == -1 || nextComma < nextOpen) { arguments.add(string.substring(0, nextComma)); string.replace(0, nextComma + 1, ""); } else { // nextOpen < nextComma int depth = 1; int index = nextOpen; while (depth > 0 && index < string.length() - 1) { char nextChar = string.charAt(++index); if ('<' == nextChar) { ++depth; } else if ('>' == nextChar) { --depth; } } arguments.add(string.substring(0, index + 1)); string.replace(0, index + 1, ""); } } return arguments.toArray(new String[arguments.size()]); } }