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 {
      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()]);
}

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 { 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 ( ) ] ) ; }
splits the provided string of nested types into separate top - level instances .
