org.openbp.common.util
Class NamedObjectCollectionUtil

java.lang.Object
  extended by org.openbp.common.util.NamedObjectCollectionUtil

public final class NamedObjectCollectionUtil
extends java.lang.Object

Static utilitiy methods for managing collections of NamedObject objects.

Author:
Erich Lauterbach

Method Summary
static java.lang.String createUniqueId(java.util.Collection toInsert, java.util.Collection inserted, java.util.Collection base, java.lang.String typeName)
          Creates a unique id among objects in two collections.
static java.lang.String createUniqueId(java.util.Collection c, java.lang.String typeName)
          Creates a unique id among objects in a collection beginning with the specified type name.
static void createUniqueName(DescriptionObject element, java.util.Collection base)
          Renames the given element in such a way, that the element name doesn't conflict with an element of the given collection.
static void createUniqueNames(java.util.Collection toInsert, java.util.Collection base)
          Renames the elements of the first collection in such a way, that the element names do not conflict with the elements of the given base collection.
static DescriptionObject getByName(java.util.Collection c, java.lang.String name)
          Searches a collection for an object with a particular name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getByName

public static DescriptionObject getByName(java.util.Collection c,
                                          java.lang.String name)
Searches a collection for an object with a particular name. The object must implement the DescriptionObject interface in order to be found. Objects that do not implement this interface will be skipped.

Parameters:
c - Collection to search or null
name - Object name to search for or null
Returns:
The found object or null if no such object exists

createUniqueId

public static java.lang.String createUniqueId(java.util.Collection c,
                                              java.lang.String typeName)
Creates a unique id among objects in a collection beginning with the specified type name. The method ensures that the id is unique within the collection by appending a number at the end of the type name.

Parameters:
c - Collection containing DescriptionObject items
typeName - The type name to use as base name
Returns:
The generated names will start with the sequence number 1.
E. g. for the typeName "ident" the method will return names like "ident", "ident2", "ident3", ...

createUniqueId

public static java.lang.String createUniqueId(java.util.Collection toInsert,
                                              java.util.Collection inserted,
                                              java.util.Collection base,
                                              java.lang.String typeName)
Creates a unique id among objects in two collections. The returned name is either the original, if that name is not yet present in the second (base) collection or a variant of the name that is not present in EITHER collection. The method ensures that the id is unique within the collection by appending a number at the end of the type name. Use this method if you want to insert a number of elements from one collection into another.

Parameters:
toInsert - Collection containing DescriptionObject items that shall be inserted into the target
inserted - Collection containing DescriptionObject items that have been inserted into the target (but are not present yet in the base collection)
base - Collection containing DescriptionObject items already present in the target
typeName - The type name to use as base name, should be a name present in insert
Returns:
The generated names will start with the sequence number 1.
E. g. for the typeName "ident" the method will return names like "ident", "ident2", "ident3", ...

createUniqueNames

public static void createUniqueNames(java.util.Collection toInsert,
                                     java.util.Collection base)
Renames the elements of the first collection in such a way, that the element names do not conflict with the elements of the given base collection. If a name does not qualify, a number is appended in order to cope. Note that the contents of the second collection are NOT changed during this process.

Parameters:
toInsert - Changeable collection of DescriptionObject items
base - Collection of DescriptionObject items

createUniqueName

public static void createUniqueName(DescriptionObject element,
                                    java.util.Collection base)
Renames the given element in such a way, that the element name doesn't conflict with an element of the given collection. If a name does not qualify, a number is appended in order to cope. Note that the contents of the second collection are NOT changed during this process.

Parameters:
element - Element to rename
base - Collection of DescriptionObject items


Copyright © 2011. All Rights Reserved.