org.knime.core.util
Class UniqueNameGenerator

java.lang.Object
  extended by org.knime.core.util.UniqueNameGenerator

public final class UniqueNameGenerator
extends Object

Helper class to create a set of unique names. Unique names are created by appending a suffix (#<index>) to duplicate names. The name set is initially created either based on a DataTableSpec (names derived from column headers) or based on a Set of strings.

This class is probably mostly used to append a set of new columns to an existing DataTableSpec.

Author:
Bernd Wiswedel, KNIME.com, Zurich, Switzerland

Constructor Summary
UniqueNameGenerator(DataTableSpec spec)
          Create name generator, with names reserved from column names.
UniqueNameGenerator(Set<String> names)
          Create new name generator with reserved names from argument set.
 
Method Summary
 DataColumnSpec newColumn(String suggested, DataType type)
          Call newCreator(String, DataType) and returns the spec created from it.
 DataColumnSpecCreator newCreator(String suggested, DataType type)
          Convenience method to create a new column spec creator with a unique name, see newName(String) for a description on how names are made unique.
 String newName(String suggested)
          Create new unique name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UniqueNameGenerator

public UniqueNameGenerator(DataTableSpec spec)
Create name generator, with names reserved from column names.

Parameters:
spec - The spec whose name are the initially set of names.

UniqueNameGenerator

public UniqueNameGenerator(Set<String> names)
Create new name generator with reserved names from argument set.

Parameters:
names - Reserved names, must not be null.
Method Detail

newName

public String newName(String suggested)
Create new unique name. The returned name is guaranteed to be unique, subsequent calls to this method with the same argument will return a different unique name.

Parameters:
suggested - The name as suggested
Returns:
Either the argument if it's already unique or a derivation of the argument, which is unique.
Throws:
NullPointerException - If the argument is null.

newCreator

public DataColumnSpecCreator newCreator(String suggested,
                                        DataType type)
Convenience method to create a new column spec creator with a unique name, see newName(String) for a description on how names are made unique.

Parameters:
suggested - The base name
type - The target column type.
Returns:
A column spec creator with the name 'uniquified'.

newColumn

public DataColumnSpec newColumn(String suggested,
                                DataType type)
Call newCreator(String, DataType) and returns the spec created from it.

Parameters:
suggested - The base name
type - The column type.
Returns:
A column with a unique name.


Copyright, 2003 - 2012. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.