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

📄 bsconsumerlist.java

📁 一款即时通讯软件
💻 JAVA
字号:
package edu.ou.kmi.buddyspace.core;

/*
 * BSConsumerList.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2003
 *
 *
 * Created on 13 May 2003, 13:42
 */

import java.util.*;

/**
 * <code>BSConsumerList</code> is list of packet/event consumers devided into
 * several levels of priority. 
 * The priority level are numbers from 0 to levelNum-1.
 * The higher number, the higher priority.
 *
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 */
public class BSConsumerList {
    
    Vector levels[];
    int levelNum;
    
    public BSConsumerList(int levelNum) {
        this.levelNum = levelNum;
        levels = new Vector[levelNum];
        for (int i=0; i<levelNum; i++)
            levels[i] = new Vector();
    }
    
    
    /** Inserts the object as the last one in given level */
    public void addLast(Object object, int level) 
                throws ArrayIndexOutOfBoundsException {
                    
        if (level < 0 || level >= levelNum)
            throw new ArrayIndexOutOfBoundsException(level);
        
        levels[level].add(object);
    }
    
    
    /** Inserts the object as the first one in given level */
    public void addFirst(Object object, int level) 
                throws ArrayIndexOutOfBoundsException {
                    
        if (level < 0 || level >= levelNum)
            throw new ArrayIndexOutOfBoundsException(level);
        
        levels[level].add(levels[level].size(), object);
    }
    
    
    /** Returns list of all objects sorted according to their priority and
     * the order in each priority level. */
    public Enumeration getConsumers() {
        Vector result = new Vector();
        
        for (int i=levelNum-1; i>=0; i--)
            result.addAll(levels[i]);
        
        return result.elements();
    }
    
    
    /** Removes occurence of the object with the highest priority */
    public boolean remove(Object object) {
        for (int i=levelNum-1; i>=0; i--)
            if (levels[i].remove(object)) return true;
        
        return false;
    }
    
    
    /** Removes occurence of the object with the highest priority on given level */
    public boolean remove(Object object, int level) 
                throws ArrayIndexOutOfBoundsException {
                    
        if (level < 0 || level >= levelNum)
            throw new ArrayIndexOutOfBoundsException(level);
        
        return levels[level].remove(object);
    }
    
    
    /** Removes all consumers */
    public void clear() {
        for (int i=levelNum-1; i>=0; i--)
            levels[i].clear();
    }
    
    
    /** Returns if the consumer list contains the object */
    public boolean contains(Object object) {
        for (int i=levelNum-1; i>=0; i--)
            if (levels[i].contains(object)) return true;
        
        return false;
    }
    
    
    /** Returns if the consumer list contains the object on given level */
    public boolean contains(Object object, int level) 
                throws ArrayIndexOutOfBoundsException {
                    
        if (level < 0 || level >= levelNum)
            throw new ArrayIndexOutOfBoundsException(level);
        
        return levels[level].contains(object);
    }
    
    
    
}

⌨️ 快捷键说明

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