/**
   * Determines a unique suffix for the given name that will make the item name unique.
   *
   * @param item Item to generate a name for
   * @param name Name to use as base for the new name
   * @return The suffix ("1", "2", ... according to names like "name", "name2", ...) or null if the
   *     supplied name is already unique
   */
  public String determineUniqueSuffix(final Item item, final String name) {
    Model model = item.getModel();
    String itemType = item.getItemType();

    Iterator itemIterator = model.getItems(itemType);
    List items = new ArrayList();
    CollectionUtil.addAll(items, itemIterator);

    String result = NamedObjectCollectionUtil.createUniqueId(items, name);
    if (result.equals(name)) return null;
    return result.substring(name.length());
  }
Exemple #2
0
  /**
   * This method tokenizes the passed string using the given separator and returns the resulting
   * fragment as a String array.
   *
   * @param string The string to be tokenized
   * @param separator The separator
   * @param trim true The tokens have been trimmed before the were added<br>
   *     false The raw tokens will be used
   * @return The fragments of the string
   */
  public static String[] tokenize(String string, String separator, boolean trim) {
    StringTokenizer tokenizer = new StringTokenizer(string, separator);

    ArrayList parts = new ArrayList();
    while (tokenizer.hasMoreTokens()) {
      String token = tokenizer.nextToken();

      if (trim) token = token.trim();

      parts.add(token);
    }

    return CollectionUtil.toStringArray(parts);
  }