public GenericMatchInfo findBestMatch ( String text , int start , EnumSet < GenericNameType > genericTypes ) { if ( text == null || text . length ( ) == 0 || start < 0 || start >= text . length ( ) ) { throw new IllegalArgumentException ( "bad input text or range" ) ; } GenericMatchInfo bestMatch = null ; // Find matches in the TimeZoneNames first Collection < MatchInfo > tznamesMatches = findTimeZoneNames ( text , start , genericTypes ) ; if ( tznamesMatches != null ) { MatchInfo longestMatch = null ; for ( MatchInfo match : tznamesMatches ) { if ( longestMatch == null || match . matchLength ( ) > longestMatch . matchLength ( ) ) { longestMatch = match ; } } if ( longestMatch != null ) { bestMatch = createGenericMatchInfo ( longestMatch ) ; if ( bestMatch . matchLength ( ) == ( text . length ( ) - start ) ) { // Full match //return bestMatch; // TODO Some time zone uses a same name for the long standard name // and the location name. When the match is a long standard name, // then we need to check if the name is same with the location name. // This is probably a data error or a design bug. // if (bestMatch.nameType != GenericNameType.LONG || bestMatch.timeType != TimeType.STANDARD) { // return bestMatch; // } // TODO The deprecation of commonlyUsed flag introduced the name // conflict not only for long standard names, but short standard names too. // These short names (found in zh_Hant) should be gone once we clean // up CLDR time zone display name data. Once the short name conflict // problem (with location name) is resolved, we should change the condition // below back to the original one above. -Yoshito (2011-09-14) if ( bestMatch . timeType != TimeType . STANDARD ) { return bestMatch ; } } } } // Find matches in the local trie Collection < GenericMatchInfo > localMatches = findLocal ( text , start , genericTypes ) ; if ( localMatches != null ) { for ( GenericMatchInfo match : localMatches ) { // TODO See the above TODO. We use match.matchLength() >= bestMatch.matcheLength() // for the reason described above. //if (bestMatch == null || match.matchLength() > bestMatch.matchLength()) { if ( bestMatch == null || match . matchLength ( ) >= bestMatch . matchLength ( ) ) { bestMatch = match ; } } } return bestMatch ; }
Returns the best match of time zone display name for the specified types in the given text at the given offset .