code: public static String checkSameNameStyle( List<StyleWrapper> styles, String styleName ) {
          int index = 1;
          String name = styleName.trim();
          for( int i = 0; i < styles.size(); i++ ) {
              StyleWrapper styleWrapper = styles.get(i);
              String tmpName = styleWrapper.getName();
              if (tmpName == null) {
                  continue;
              }
  
              tmpName = tmpName.trim();
              if (tmpName.equals(name)) {
                  // name exists, change the name of the entering
                  if (name.endsWith(")")) {
                      name = name.trim().replaceFirst("\\([0-9]+\\)$", "(" + (index++) + ")");
                  } else {
                      name = name + " (" + (index++) + ")";
                  }
                  // start again
                  i = 0;
              }
              if (index == 1000) {
                  // something odd is going on
                  throw new RuntimeException();
              }
          }
          return name;
      }
docs: Checks if the list of {@link StyleWrapper}s supplied contains one with the supplied name.
  
  <p>If the style is contained it adds an index to the name.
  
  @param styles the list of style wrappers to check.
  @param styleName the name of the style to find.
  @return the new name of the style.