Java Collection Unique getUniqueNameWithNumbers(Collection names, String baseName)

Here you can find the source of getUniqueNameWithNumbers(Collection names, String baseName)

Description

get Unique Name With Numbers

License

MIT License

Declaration

public static String getUniqueNameWithNumbers(Collection<String> names, String baseName) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *  Copyright ? 2012-2015 eBay Software Foundation
 *  This program is dual licensed under the MIT and Apache 2.0 licenses.
 *  Please see LICENSE for more information.
 *******************************************************************************/

import java.util.Collection;

public class Main {
    public static String getUniqueNameWithNumbers(Collection<String> names, String baseName) {
        if (names == null) {
            return baseName;
        }// w  w w .jav a 2s .  co m
        String name = baseName;
        int i = 1;
        while (names.contains(name)) {
            name = baseName + i;
            i++;
        }
        return name;
    }
}

Related

  1. addUnique(final Collection collection, final Object value)
  2. generateUniqueName(String aName, Collection aStringCollection)
  3. getUnique(Collection c)
  4. getUnique(Collection collection)
  5. getUniqueName(String name, Collection collection)
  6. getUniqueValue(Collection values, String initValue)
  7. hasUniqueObject(Collection collection)
  8. hasUniqueObject(Collection collection)
  9. hasUniqueObject(Collection collection)