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

📄 groupcollection.java

📁 基于Jabber协议的即时消息服务器
💻 JAVA
字号:
/** * $Revision: 691 $ * $Date: 2004-12-13 15:06:54 -0300 (Mon, 13 Dec 2004) $ * * Copyright (C) 2004-2006 Jive Software. All rights reserved. * * This software is published under the terms of the GNU Public License (GPL), * a copy of which is included in this distribution. */package org.jivesoftware.wildfire.group;import java.util.AbstractCollection;import java.util.Iterator;import java.util.NoSuchElementException;import java.util.Collection;/** * Provides a view of an array of group names as a Collection of Group objects. If * any of the group names cannot be loaded, they are transparently skipped when * iterating over the collection. * * @author Matt Tucker */public class GroupCollection extends AbstractCollection {    private String[] elements;    /**     * Constructs a new GroupCollection.     */    public GroupCollection(Collection<String> collection) {        this.elements = collection.toArray(new String[collection.size()]);    }    /**     * Constructs a new GroupCollection.     */    public GroupCollection(String [] elements) {        this.elements = elements;    }    public Iterator iterator() {        return new UserIterator();    }    public int size() {        return elements.length;    }    private class UserIterator implements Iterator {        private int currentIndex = -1;        private Object nextElement = null;        public boolean hasNext() {            // If we are at the end of the list, there can't be any more elements            // to iterate through.            if (currentIndex + 1 >= elements.length && nextElement == null) {                return false;            }            // Otherwise, see if nextElement is null. If so, try to load the next            // element to make sure it exists.            if (nextElement == null) {                nextElement = getNextElement();                if (nextElement == null) {                    return false;                }            }            return true;        }        public Object next() throws java.util.NoSuchElementException {            Object element;            if (nextElement != null) {                element = nextElement;                nextElement = null;            }            else {                element = getNextElement();                if (element == null) {                    throw new NoSuchElementException();                }            }            return element;        }        public void remove() throws UnsupportedOperationException {            throw new UnsupportedOperationException();        }        /**         * Returns the next available element, or null if there are no more elements to return.         *         * @return the next available element.         */        private Object getNextElement() {            while (currentIndex + 1 < elements.length) {                currentIndex++;                Object element = null;                try {                    element = GroupManager.getInstance().getGroup(elements[currentIndex]);                }                catch (GroupNotFoundException unfe) {                    // Ignore.                }                if (element != null) {                    return element;                }            }            return null;        }    }}

⌨️ 快捷键说明

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