public CharSequence format ( ) { if ( formatted == null ) { if ( ! keysToValues . keySet ( ) . containsAll ( keys ) ) { Set < String > missingKeys = new HashSet < String > ( keys ) ; missingKeys . removeAll ( keysToValues . keySet ( ) ) ; throw new IllegalArgumentException ( "Missing keys: " + missingKeys ) ; } // Copy the original pattern to preserve all spans, such as bold, italic, etc. SpannableStringBuilder sb = new SpannableStringBuilder ( pattern ) ; for ( Token t = head ; t != null ; t = t . next ) { t . expand ( sb , keysToValues ) ; } formatted = sb ; } return formatted ; }
Returns the text after replacing all keys with values .