private double[] computeShortestPathLenghts(int pStartNode,double pShortestPathLengthSum,double pMaxPathLength,Set<Integer> pWasSource){
  Set<Integer> alreadyExpanded=new HashSet<Integer>();
  List<int[]> queue=new ArrayList<int[]>();
  int[] innerList=new int[2];
  innerList[0]=pStartNode;
  innerList[1]=0;
  queue.add(innerList);
  while (!queue.isEmpty()) {
    int[] queueElement=queue.get(0);
    int currentNode=queueElement[0];
    int distance=queueElement[1];
    queue.remove(0);
    if (!alreadyExpanded.contains(currentNode)) {
      alreadyExpanded.add(currentNode);
      if (!pWasSource.contains(currentNode)) {
        pShortestPathLengthSum+=distance;
        if (distance > pMaxPathLength) {
          pMaxPathLength=distance;
        }
      }
      Set<Integer> neighbors=getNeighbors(currentNode);
      for (      int neighbor : neighbors) {
        if (!alreadyExpanded.contains(neighbor)) {
          int[] tmpList=new int[2];
          tmpList[0]=neighbor;
          tmpList[1]=(distance + 1);
          queue.add(tmpList);
        }
      }
    }
  }
  double returnArray[]={pShortestPathLengthSum,pMaxPathLength};
  return returnArray;
}

private double [ ] computeShortestPathLenghts ( int pStartNode , double pShortestPathLengthSum , double pMaxPathLength , Set < Integer > pWasSource ) { Set < Integer > alreadyExpanded = new HashSet < Integer > ( ) ; List < int [ ] > queue = new ArrayList < int [ ] > ( ) ; int [ ] innerList = new int [ 2 ] ; innerList [ 0 ] = pStartNode ; innerList [ 1 ] = 0 ; queue . add ( innerList ) ; while ( ! queue . isEmpty ( ) ) { int [ ] queueElement = queue . get ( 0 ) ; int currentNode = queueElement [ 0 ] ; int distance = queueElement [ 1 ] ; queue . remove ( 0 ) ; if ( ! alreadyExpanded . contains ( currentNode ) ) { alreadyExpanded . add ( currentNode ) ; if ( ! pWasSource . contains ( currentNode ) ) { pShortestPathLengthSum += distance ; if ( distance > pMaxPathLength ) { pMaxPathLength = distance ; } } Set < Integer > neighbors = getNeighbors ( currentNode ) ; for ( int neighbor : neighbors ) { if ( ! alreadyExpanded . contains ( neighbor ) ) { int [ ] tmpList = new int [ 2 ] ; tmpList [ 0 ] = neighbor ; tmpList [ 1 ] = ( distance + 1 ) ; queue . add ( tmpList ) ; } } } } double returnArray [ ] = { pShortestPathLengthSum , pMaxPathLength } ; return returnArray ; }
computes the shortest path from node to all other nodes . paths to nodes that have already been the source of the shortest path computation are omitted ( the path was already added to the path sum ) . updates the sum of shortest path lengths and the diameter of the graph . as the jgrapht breadthfirstiterator does not provide information about the distance to the start node in each step , we will use our own bfs implementation .
