⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 options.java

📁 In the last three articles, I’ve been walking you through the creation of an end-to-end BlackBerry a
💻 JAVA
字号:
package KnowledgeBase;

import net.rim.device.api.system.*;
import net.rim.device.api.collection.util.*;

class DataStore {
   
   private static PersistentObject store;
   private static DataStore instance;
   private LongHashtableCollection  settings;
   
   private static final long KEY_APP_SRV_URL = 0;
   private static final long KEY_MAX_CACHED_ARTICLES = 1;
   private static final long KEY_CACHED_ARTICLES = 3;
   
   
   
   private static String DEFAULT_SERVICE_URL = "";
   private static int DEFAULT_MAX_CACHED_ARTICLES = 15;
   
   private static DataStore getInstance() {
        if (null == instance) {
            instance = new DataStore();
        }
        return instance; 
    }
    
    private DataStore() {
        store = PersistentStore.getPersistentObject(0xf6354ee14c6cc857L);
    }
    
    public static String getAppServerUrl() {
       String url = (String)getInstance().get(KEY_APP_SRV_URL);
       if (null == url || url.length() == 0) {
         url =  DEFAULT_SERVICE_URL; 
         setAppServerUrl(url);
       }
       return url;
    }
   
    public static void setAppServerUrl(String url) {
       getInstance().set(KEY_APP_SRV_URL,url);
    } 
    
    public static int getMaxCachedArticles() {
       int maxCachedArticles;
       String maxCachedArticlesString = 
                (String)getInstance().get(KEY_MAX_CACHED_ARTICLES);
        if (null == maxCachedArticlesString || 
            maxCachedArticlesString.length() == 0) {
            maxCachedArticles =  DEFAULT_MAX_CACHED_ARTICLES; 
            setMaxCachedArticles(maxCachedArticles);
        } else {
            maxCachedArticles = Integer.parseInt(maxCachedArticlesString);
        }
       return maxCachedArticles;
    }
   
    public static void setMaxCachedArticles(int maxCachedArticles) {
       getInstance().set(KEY_MAX_CACHED_ARTICLES,String.valueOf(maxCachedArticles));
    } 
    
    public static Article[] getCachedArticles() {
        Article[] articles = (Article[])getInstance().get(KEY_CACHED_ARTICLES);
       if (null == articles ) {
         articles =  new Article[0]; 
         setCachedArticles(articles);
       }
       return articles;
    }
    
    public static void setCachedArticles(Article[] articles) {
       getInstance().set(KEY_CACHED_ARTICLES,articles);
    } 
    
    private void set(long key, Object value) {
        synchronized(store) {
            settings = (LongHashtableCollection)store.getContents();
            if (null == settings) {
                settings = new LongHashtableCollection();
            }
            settings.put(key,value);   
            store.setContents(settings);
            store.commit();
        }
    }    
    
    private Object get(long key) {
        synchronized(store) {
            settings = (LongHashtableCollection)store.getContents();
            if (null != settings && settings.size() != 0) {
                 return settings.get(key);
            } else {
                 return null;
            }
        }
    }
   
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -