@ NotNull private List < String > getFormattedConversions ( List < Map . Entry < Unit , Double > > conversions ) { List < String > formatted = new ArrayList <> ( ) ; for ( Map . Entry < Unit , Double > equivalent : conversions ) { Unit metric = equivalent . getKey ( ) ; double converted = equivalent . getValue ( ) ; long rounded = Math . round ( converted ) ; for ( String symbol : unitSymbols . getOrDefault ( metric , new ArrayList <> ( ) ) ) { if ( formatted . size ( ) > MAX_SUGGESTIONS ) { break ; } if ( Math . abs ( converted - rounded ) / Math . abs ( converted ) < ROUNDING_DELTA && rounded != 0 ) { String formattedStr = formatRounded ( getNumberFormat ( ) . format ( rounded ) + " " + symbol ) ; if ( ! formatted . contains ( formattedStr ) ) { formatted . add ( formattedStr ) ; } } String formattedNumber = getNumberFormat ( ) . format ( converted ) ; String formattedStr = formattedNumber + " " + symbol ; // TODO: be cleverer than !equals("0"), can prevent valid conversions if ( ! formatted . contains ( formattedStr ) && ! formattedNumber . equals ( "0" ) ) { formatted . add ( formattedStr ) ; } } } return formatted ; }
Adds different formatted variants of the given conversions up to MAX_SUGGESTIONS .