public int numberOfDisconnectedGroups(Collection<String> genomes){
  final String[] genomes2=genomes.toArray(new String[genomes.size()]);
  final int[] connectionsMatrix=new int[genomes.size() * genomes.size()];
  final HashSet<Integer> groupIds=new HashSet<>();
  for (int j=0; j < genomes2.length; j++) {
    int min=j + 1;
    final String g1=genomes2[j];
    for (int i=0; i < genomes2.length; i++) {
      final String g2=genomes2[i];
      if (areRelated(g1,g2)) {
        connectionsMatrix[j * genomes2.length + i]=j + 1;
        for (int k=0; k < j; k++) {
          final int value=connectionsMatrix[k * genomes2.length + i];
          if (value != 0 && value < min) {
            min=value;
          }
        }
      }
    }
    for (int i=0; i < genomes2.length; i++) {
      if (connectionsMatrix[j * genomes2.length + i] != 0) {
        connectionsMatrix[j * genomes2.length + i]=min;
        groupIds.add(min);
      }
    }
  }
  return groupIds.size();
}

public int numberOfDisconnectedGroups ( Collection < String > genomes ) { final String [ ] genomes2 = genomes . toArray ( new String [ genomes . size ( ) ] ) ; final int [ ] connectionsMatrix = new int [ genomes . size ( ) * genomes . size ( ) ] ; final HashSet < Integer > groupIds = new HashSet < > ( ) ; for ( int j = 0 ; j < genomes2 . length ; j ++ ) { int min = j + 1 ; final String g1 = genomes2 [ j ] ; for ( int i = 0 ; i < genomes2 . length ; i ++ ) { final String g2 = genomes2 [ i ] ; if ( areRelated ( g1 , g2 ) ) { connectionsMatrix [ j * genomes2 . length + i ] = j + 1 ; for ( int k = 0 ; k < j ; k ++ ) { final int value = connectionsMatrix [ k * genomes2 . length + i ] ; if ( value != 0 && value < min ) { min = value ; } } } } for ( int i = 0 ; i < genomes2 . length ; i ++ ) { if ( connectionsMatrix [ j * genomes2 . length + i ] != 0 ) { connectionsMatrix [ j * genomes2 . length + i ] = min ; groupIds . add ( min ) ; } } } return groupIds . size ( ) ; }
returns a count of the distinct groups that the given genomes represent within the current pedigree .
