Code example for TreeMap

Methods: get, put

0
public class TypeFaceHelper { 
 
    private static TreeMap<String, Typeface> mTypefaceCache = new TreeMap<String, Typeface>();  
 
    public static Typeface createFromAsset(Context context, String path) {
        Typeface tf = mTypefaceCache.get(path);
        if (tf != null)
            return tf;
         
        AssetManager am = context.getAssets();
        if (am == null)
            return null; 
         
        try { 
            tf = Typeface.createFromAsset(am, path);
            mTypefaceCache.put(path, tf);
        } catch (RuntimeException e) {
            mTypefaceCache.put(path, null);
        } 
         
        return tf;
    } 
}