question: private Map < URI , Map < URI , Map < String , List < URI > > > > createDeviceToCGMapFromDescriptors ( List < VolumeDescriptor > addDescriptors , List < VolumeDescriptor > removeDescriptors ) { Map < URI , Map < URI , Map < String , List < URI > > > > deviceToCGMap = new HashMap < URI , Map < URI , Map < String , List < URI > > > > ( ) ; for ( VolumeDescriptor descr : addDescriptors ) { URI deviceURI = descr . getDeviceURI ( ) ; Map < URI , Map < String , List < URI > > > volumesToUpdateByCG = deviceToCGMap . get ( deviceURI ) ; if ( volumesToUpdateByCG == null ) { volumesToUpdateByCG = new HashMap < URI , Map < String , List < URI > > > ( ) ; deviceToCGMap . put ( deviceURI , volumesToUpdateByCG ) ; } URI consistencyGroupURI = descr . getConsistencyGroupURI ( ) ; Map < String , List < URI > > volumesToUpdate = volumesToUpdateByCG . get ( consistencyGroupURI ) ; if ( volumesToUpdate == null ) { volumesToUpdate = new HashMap < String , List < URI > > ( ) ; volumesToUpdateByCG . put ( consistencyGroupURI , volumesToUpdate ) ; } List < URI > volumesToAdd = volumesToUpdate . get ( ADD_VOLUMES_TO_CG_KEY ) ; if ( volumesToAdd == null ) { volumesToAdd = new ArrayList < URI > ( ) ; volumesToUpdate . put ( ADD_VOLUMES_TO_CG_KEY , volumesToAdd ) ; } volumesToAdd . add ( descr . getVolumeURI ( ) ) ; } for ( VolumeDescriptor descr : removeDescriptors ) { URI deviceURI = descr . getDeviceURI ( ) ; Map < URI , Map < String , List < URI > > > volumesToUpdateByCG = deviceToCGMap . get ( deviceURI ) ; if ( volumesToUpdateByCG == null ) { volumesToUpdateByCG = new HashMap < URI , Map < String , List < URI > > > ( ) ; deviceToCGMap . put ( deviceURI , volumesToUpdateByCG ) ; } URI consistencyGroupURI = descr . getConsistencyGroupURI ( ) ; Map < String , List < URI > > volumesToUpdate = volumesToUpdateByCG . get ( consistencyGroupURI ) ; if ( volumesToUpdate == null ) { volumesToUpdate = new HashMap < String , List < URI > > ( ) ; volumesToUpdateByCG . put ( consistencyGroupURI , volumesToUpdate ) ; } List < URI > volumesToRemove = volumesToUpdate . get ( REMOVE_VOLUMES_FROM_CG_KEY ) ; if ( volumesToRemove == null ) { volumesToRemove = new ArrayList < URI > ( ) ; volumesToUpdate . put ( REMOVE_VOLUMES_FROM_CG_KEY , volumesToRemove ) ; } volumesToRemove . add ( descr . getVolumeURI ( ) ) ; } return deviceToCGMap ; }
target:  Convenience method to create a map Device to CG to Volume to ADD and REMOVE. We want the map to contain both the volumes to ADD and REMOVE segregated by device and also by CG. The map will look like the below: Device URI --> CG URI ----> ADD -> List of Volumes to Add from this CG for this device ----> REMOVE -> List of Volumes to Remove from this CG for this device