private Match matchImpl ( List < Entry > desiredLocales , int threshold ) { int bestDistance = MAX_DISTANCE ; Entry bestMatch = null ; for ( Entry desired : desiredLocales ) { List < String > exact = exactMatch . get ( desired . locale ) ; if ( exact != null ) { return new Match ( exact . get ( 0 ) , 0 ) ; } for ( Entry supported : supportedLocales ) { int distance = DISTANCE_TABLE . distance ( desired . locale , supported . locale , threshold ) ; if ( distance < bestDistance ) { bestDistance = distance ; bestMatch = supported ; } } } return bestMatch == null ? new Match ( firstEntry . bundleId , MAX_DISTANCE ) : new Match ( bestMatch . bundleId , bestDistance ) ; }
Return the best match that exceeds the threshold or the default . If the default is returned its distance is set to MAX_DISTANCE . An exact match has distance of 0 .