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

📄 flagqueue.java

📁 The Funambol J2ME Mail Client aims to be a light, easy to use, free email client for J2ME devices.
💻 JAVA
字号:
/*
 * Copyright (C) 2006-2007 Funambol
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.funambol.mailclient.syncml;

import com.funambol.mail.MessageFlags;
import com.funambol.storage.ComplexSerializer;
import com.funambol.util.Log;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Hashtable;

/**
 * A class to store deleted/updated item lists
 */
public class FlagQueue {
    
    //---------------------------------------------------------------- Constants
    
    //------------------------------------------------------------- Private Data
    /** List of updated items*/
    private static Hashtable updatedItemsList = null;
    /** List of deleted items*/
    private static Hashtable deletedItemsList = null;
    
    //--------------------------------------------------------------- Properties
    
    //------------------------------------------------------------- Constructors
    /**
     * Creates a new instance of FlagQueue
     * private access: this class just shows static methods
     */
    private FlagQueue() {
        
    }
    
    
    /** initializes private items lists*/
    private static void init() {
        updatedItemsList = new Hashtable();
        deletedItemsList = new Hashtable();
    }
    
    /** reset items lists */
    public static void clear() {
        Log.debug("Clearing flag queues...");
        updatedItemsList = null;
        deletedItemsList = null;
    }
    
    
    /**
     * Put a new updated or deleted element on the related list
     * @param key is the key of th item to be delated or replaced on the server
     * @param mf is the MessageFlags related to the give item object
     */
    public static void put(String key, MessageFlags mf) {
        if (updatedItemsList==null||deletedItemsList==null) {
            init();
        }
        selectList(mf).put(key, mf);
        //if a message has been updated and deleted before the next sync,
        //it is shown on deleted item list only
        if (updatedItemsList.containsKey(key)&&deletedItemsList.containsKey(key)) {
            updatedItemsList.remove(key);
        }
    }
    
    /**
     * Removes an element from the list
     * @param key the key of the item to be removed
     */
    public static void remove(String key) {
        if (deletedItemsList!=null) {
            if (deletedItemsList.containsKey(key)) {
                deletedItemsList.remove(key);
                return;
            }
        }
        if (updatedItemsList!=null) {
            //if (updatedItemsList.containsKey(key)) {
            updatedItemsList.remove(key);
            //}
        }
    }
    
    /**
     * Accesses the item list by item's @param key and gets the related item
     *
     * @param key the key of the message of which the flags are requested
     * @return the flags of the specified key, or null if not found
     */
    public static MessageFlags get(String key) {
        if (deletedItemsList.containsKey(key)) {
            return (MessageFlags) deletedItemsList.get(key);
        } else if (updatedItemsList.containsKey(key)) {
            return (MessageFlags) updatedItemsList.get(key);
        }
        return null;
    }
    
    /**
     * @return Hashtable representing the list of updated items
     */
    public static Hashtable getUpdatedItemsList() {
        return updatedItemsList==null?new Hashtable():updatedItemsList;
    }
    
    /**
     * @return Hashtable representing the list of deleted items
     */
    public static Hashtable getDeletedItemsList() {
        return deletedItemsList==null?new Hashtable():deletedItemsList;
    }
    
    /**
     * Select the list to be updated given the @param mf MessaFlags object
     */
    private static Hashtable selectList(MessageFlags mf) {
        if (mf.isSet(MessageFlags.DELETED)) {
            return deletedItemsList;
        }
        return updatedItemsList;
    }
}

⌨️ 快捷键说明

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