@ Nullable public String getUniqueID ( @ Nullable final String sID ) { if ( sID == null ) return null ; if ( m_aUsedIDs . add ( sID ) ) { // Unique ID return sID ; } // Non-unique ID int nIndex = 0 ; String sNewID = sID + nIndex ; do { if ( m_aUsedIDs . add ( sNewID ) ) { // Now it's unique return sNewID ; } ++ nIndex ; sNewID = sID + nIndex ; } while ( true ) ; }
Create a unique ID based on the passed one . If the passed ID is not yet contained than a numeric index is appended until the ID is unique .