Source Code Cross Referenced for Singleton.java in  » GIS » GeoTools-2.4.1 » org » geotools » util » 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 » GIS » GeoTools 2.4.1 » org.geotools.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2005-2006, Geotools Project Managment Committee (PMC)
005:         *    (C) 2005, Institut de Recherche pour le Développement
006:         *
007:         *    This library is free software; you can redistribute it and/or
008:         *    modify it under the terms of the GNU Lesser General Public
009:         *    License as published by the Free Software Foundation; either
010:         *    version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *    This library is distributed in the hope that it will be useful,
013:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *    Lesser General Public License for more details.
016:         */
017:        package org.geotools.util;
018:
019:        // J2SE dependencies
020:        import java.util.AbstractSet;
021:        import java.util.Iterator;
022:        import java.util.NoSuchElementException;
023:
024:        /**
025:         * A mutable set containing only one element. This set can't contains null element.
026:         *
027:         * @since 2.1
028:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/main/java/org/geotools/util/Singleton.java $
029:         * @version $Id: Singleton.java 24435 2007-02-16 03:32:10Z desruisseaux $
030:         * @author Martin Desruisseaux
031:         *
032:         * @deprecated Not used anymore in the Geotools code base. If needed, use a small
033:         *             {@link java.util.ArrayList} instead.
034:         */
035:        public class Singleton extends AbstractSet {
036:            /**
037:             * The element, or {@code null} if this set is empty.
038:             */
039:            private Object element;
040:
041:            /**
042:             * Creates a initially empty singleton.
043:             */
044:            public Singleton() {
045:            }
046:
047:            /**
048:             * Returns 1 if this singleton contains an element, or 0 otherwise.
049:             */
050:            public int size() {
051:                return (element != null) ? 1 : 0;
052:            }
053:
054:            /**
055:             * Returns {@code true} if this singleton contains no elements.<p>
056:             */
057:            public boolean isEmpty() {
058:                return element == null;
059:            }
060:
061:            /**
062:             * Returns the element in this singleton.
063:             *
064:             * @return The singleton element (never null).
065:             * @throws NoSuchElementException if this singleton is empty.
066:             */
067:            public Object get() throws NoSuchElementException {
068:                if (element == null) {
069:                    throw new NoSuchElementException();
070:                }
071:                return element;
072:            }
073:
074:            /**
075:             * Returns {@code true} if this singleton contains the specified element.
076:             */
077:            public boolean contains(final Object object) {
078:                return element != null && element.equals(object);
079:            }
080:
081:            /**
082:             * Adds the specified element to this set if it is not already present.
083:             * If this set already contains an other element, an exception is thrown.
084:             *
085:             * @throws NullPointerException if the argument is null.
086:             * @throws IllegalArgumentException if this set already contains an other element.
087:             */
088:            public boolean add(final Object object) {
089:                if (object == null) {
090:                    throw new NullPointerException();
091:                }
092:                if (element == null) {
093:                    element = object;
094:                    return true;
095:                }
096:                if (element.equals(object)) {
097:                    element = object;
098:                    return false;
099:                }
100:                throw new IllegalArgumentException();
101:            }
102:
103:            /**
104:             * Removes the specified element from this singleton, if it is present.
105:             */
106:            public boolean remove(final Object object) {
107:                if (element != null && element.equals(object)) {
108:                    element = null;
109:                    return true;
110:                }
111:                return false;
112:            }
113:
114:            /**
115:             * Removes the element from this singleton.
116:             */
117:            public void clear() {
118:                element = null;
119:            }
120:
121:            /**
122:             * Returns an iterator over the element of this singleton.
123:             */
124:            public Iterator iterator() {
125:                return new Iter();
126:            }
127:
128:            /**
129:             * The iterator for this singleton.
130:             */
131:            private final class Iter implements  Iterator {
132:                /**
133:                 * {@code false} if this iterator is done.
134:                 */
135:                private boolean hasNext;
136:
137:                /**
138:                 * Construct a new iterator.
139:                 */
140:                public Iter() {
141:                    hasNext = (element != null);
142:                }
143:
144:                /**
145:                 * Returns {@code true} if there is more element to return.
146:                 */
147:                public boolean hasNext() {
148:                    return hasNext;
149:                }
150:
151:                /**
152:                 * Returns the next element.
153:                 */
154:                public Object next() {
155:                    if (!hasNext) {
156:                        throw new NoSuchElementException();
157:                    }
158:                    hasNext = false;
159:                    return element;
160:                }
161:
162:                /**
163:                 * Remove the last element in this set.
164:                 */
165:                public void remove() {
166:                    if (hasNext) {
167:                        throw new IllegalStateException();
168:                    }
169:                    element = null;
170:                }
171:            }
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.