Source Code Cross Referenced for UserCollection.java in  » Net » openfire » org » jivesoftware » openfire » user » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » openfire » org.jivesoftware.openfire.user 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Revision: 691 $
003:         * $Date: 2004-12-13 15:06:54 -0300 (Mon, 13 Dec 2004) $
004:         *
005:         * Copyright (C) 2004-2006 Jive Software. All rights reserved.
006:         *
007:         * This software is published under the terms of the GNU Public License (GPL),
008:         * a copy of which is included in this distribution.
009:         */package org.jivesoftware.openfire.user;
010:
011:        import java.util.Iterator;
012:        import java.util.NoSuchElementException;
013:        import java.util.AbstractCollection;
014:
015:        /**
016:         * Provides a view of an array of usernames as a Collection of User objects. If
017:         * any of the usernames cannot be loaded, they are transparently skipped when
018:         * iterating over the collection.
019:         *
020:         * @author Matt Tucker
021:         */
022:        public class UserCollection extends AbstractCollection {
023:
024:            private String[] elements;
025:
026:            /**
027:             * Constructs a new UserCollection.
028:             */
029:            public UserCollection(String[] elements) {
030:                this .elements = elements;
031:            }
032:
033:            public Iterator iterator() {
034:                return new UserIterator();
035:            }
036:
037:            public int size() {
038:                return elements.length;
039:            }
040:
041:            private class UserIterator implements  Iterator {
042:
043:                private int currentIndex = -1;
044:                private Object nextElement = null;
045:
046:                public boolean hasNext() {
047:                    // If we are at the end of the list, there can't be any more elements
048:                    // to iterate through.
049:                    if (currentIndex + 1 >= elements.length
050:                            && nextElement == null) {
051:                        return false;
052:                    }
053:                    // Otherwise, see if nextElement is null. If so, try to load the next
054:                    // element to make sure it exists.
055:                    if (nextElement == null) {
056:                        nextElement = getNextElement();
057:                        if (nextElement == null) {
058:                            return false;
059:                        }
060:                    }
061:                    return true;
062:                }
063:
064:                public Object next() throws java.util.NoSuchElementException {
065:                    Object element;
066:                    if (nextElement != null) {
067:                        element = nextElement;
068:                        nextElement = null;
069:                    } else {
070:                        element = getNextElement();
071:                        if (element == null) {
072:                            throw new NoSuchElementException();
073:                        }
074:                    }
075:                    return element;
076:                }
077:
078:                public void remove() throws UnsupportedOperationException {
079:                    throw new UnsupportedOperationException();
080:                }
081:
082:                /**
083:                 * Returns the next available element, or null if there are no more elements to return.
084:                 *
085:                 * @return the next available element.
086:                 */
087:                private Object getNextElement() {
088:                    while (currentIndex + 1 < elements.length) {
089:                        currentIndex++;
090:                        Object element = null;
091:                        try {
092:                            element = UserManager.getInstance().getUser(
093:                                    elements[currentIndex]);
094:                        } catch (UserNotFoundException unfe) {
095:                            // Ignore.
096:                        }
097:                        if (element != null) {
098:                            return element;
099:                        }
100:                    }
101:                    return null;
102:                }
103:            }
104:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.