private void assignUniqueLabel ( Package pack , Package targetPackage ) { Set < String > existingLabels ; if ( targetPackage != null ) { existingLabels = stream ( targetPackage . getChildren ( ) ) . map ( Package :: getLabel ) . collect ( toSet ( ) ) ; } else { existingLabels = dataService . query ( PACKAGE , Package . class ) . eq ( PackageMetadata . PARENT , null ) . findAll ( ) . map ( Package :: getLabel ) . collect ( toSet ( ) ) ; } pack . setLabel ( generateUniqueLabel ( pack . getLabel ( ) , existingLabels ) ) ; }
Checks if there s a Package in the target location with the same label . If so keeps adding a postfix until the label is unique .