private List<StoragePort> sortPorts(List<StoragePort> storagePorts,Map<Initiator,List<StoragePort>> existingAssignments,List<StoragePort> newPorts){
  Set<URI> includedPorts=new HashSet<URI>();
  List<StoragePort> sortedPorts=new ArrayList<StoragePort>();
  Map<URI,StoragePort> portsMap=DataObjectUtils.toMap(storagePorts);
  for (int numPorts=4; numPorts >= 1; numPorts--) {
    for (    List<StoragePort> ports : existingAssignments.values()) {
      if (ports.size() >= numPorts) {
        for (        StoragePort port : ports) {
          if (!includedPorts.contains(port.getId()) && portsMap.containsKey(port.getId())) {
            sortedPorts.add(port);
            includedPorts.add(port.getId());
          }
        }
      }
    }
  }
  for (  StoragePort port : storagePorts) {
    if (!includedPorts.contains(port.getId())) {
      sortedPorts.add(port);
      includedPorts.add(port.getId());
      newPorts.add(port);
    }
  }
  if (sortedPorts.size() != storagePorts.size()) {
    _log.error("sortPorts size incorrect");
    _log.error(sortedPorts.toString());
    _log.error(storagePorts.toString());
    return null;
  }
  return sortedPorts;
}

private List < StoragePort > sortPorts ( List < StoragePort > storagePorts , Map < Initiator , List < StoragePort > > existingAssignments , List < StoragePort > newPorts ) { Set < URI > includedPorts = new HashSet < URI > ( ) ; List < StoragePort > sortedPorts = new ArrayList < StoragePort > ( ) ; Map < URI , StoragePort > portsMap = DataObjectUtils . toMap ( storagePorts ) ; for ( int numPorts = 4 ; numPorts >= 1 ; numPorts -- ) { for ( List < StoragePort > ports : existingAssignments . values ( ) ) { if ( ports . size ( ) >= numPorts ) { for ( StoragePort port : ports ) { if ( ! includedPorts . contains ( port . getId ( ) ) && portsMap . containsKey ( port . getId ( ) ) ) { sortedPorts . add ( port ) ; includedPorts . add ( port . getId ( ) ) ; } } } } } for ( StoragePort port : storagePorts ) { if ( ! includedPorts . contains ( port . getId ( ) ) ) { sortedPorts . add ( port ) ; includedPorts . add ( port . getId ( ) ) ; newPorts . add ( port ) ; } } if ( sortedPorts . size ( ) != storagePorts . size ( ) ) { _log . error ( "sortPorts size incorrect" ) ; _log . error ( sortedPorts . toString ( ) ) ; _log . error ( storagePorts . toString ( ) ) ; return null ; } return sortedPorts ; }
sorts the existing ports by the way they were previously grouped in existingassignments , with initiators having the most ports first and the least ports last . finally adds in the newly allocated ports and returns them in newports .
