public static int computeLatestAvailableVersionFromVersionSpec(TreeSet<Integer> allAvailableFacebookAppVersions,int latestSdkVersion,int[] versionSpec){
  int versionSpecIndex=versionSpec.length - 1;
  Iterator<Integer> fbAppVersionsIterator=allAvailableFacebookAppVersions.descendingIterator();
  int latestFacebookAppVersion=-1;
  while (fbAppVersionsIterator.hasNext()) {
    int fbAppVersion=fbAppVersionsIterator.next();
    latestFacebookAppVersion=Math.max(latestFacebookAppVersion,fbAppVersion);
    while (versionSpecIndex >= 0 && versionSpec[versionSpecIndex] > fbAppVersion) {
      versionSpecIndex--;
    }
    if (versionSpecIndex < 0) {
      return NO_PROTOCOL_AVAILABLE;
    }
    if (versionSpec[versionSpecIndex] == fbAppVersion) {
      return (versionSpecIndex % 2 == 0 ? Math.min(latestFacebookAppVersion,latestSdkVersion) : NO_PROTOCOL_AVAILABLE);
    }
  }
  return NO_PROTOCOL_AVAILABLE;
}

public static int computeLatestAvailableVersionFromVersionSpec ( TreeSet < Integer > allAvailableFacebookAppVersions , int latestSdkVersion , int [ ] versionSpec ) { int versionSpecIndex = versionSpec . length - 1 ; Iterator < Integer > fbAppVersionsIterator = allAvailableFacebookAppVersions . descendingIterator ( ) ; int latestFacebookAppVersion = - 1 ; while ( fbAppVersionsIterator . hasNext ( ) ) { int fbAppVersion = fbAppVersionsIterator . next ( ) ; latestFacebookAppVersion = Math . max ( latestFacebookAppVersion , fbAppVersion ) ; while ( versionSpecIndex >= 0 && versionSpec [ versionSpecIndex ] > fbAppVersion ) { versionSpecIndex -- ; } if ( versionSpecIndex < 0 ) { return NO_PROTOCOL_AVAILABLE ; } if ( versionSpec [ versionSpecIndex ] == fbAppVersion ) { return ( versionSpecIndex % 2 == 0 ? Math . min ( latestFacebookAppVersion , latestSdkVersion ) : NO_PROTOCOL_AVAILABLE ) ; } } return NO_PROTOCOL_AVAILABLE ; }
this is public to allow for testing . developers are discouraged from using this method , since it may change without notice .
