Source Code Cross Referenced for NiceIterator.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » util » iterator » 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 » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.util.iterator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:          (c) Copyright 2003, 2004, 2005 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:          [See end of file]
004:          $Id: NiceIterator.java,v 1.17 2008/01/02 12:07:36 andy_seaborne Exp $
005:         */
006:
007:        package com.hp.hpl.jena.util.iterator;
008:
009:        import java.util.*;
010:
011:        /**
012:         NiceIterator is the standard base class implementing ExtendedIterator. It provides
013:         the static methods for <code>andThen</code>, <code>filterKeep</code> and
014:         <code>filterDrop</code>; these can be reused from any other class. It defines
015:         equivalent instance methods for descendants and to satisfy ExtendedIterator.  
016:         @author kers
017:         */
018:
019:        public class NiceIterator implements  ExtendedIterator {
020:            public NiceIterator() {
021:                super ();
022:            }
023:
024:            /**
025:                default close: don't need to do anything.
026:             */
027:            public void close() {
028:            }
029:
030:            /**
031:                default hasNext: no elements, return false.
032:             */
033:            public boolean hasNext() {
034:                return false;
035:            }
036:
037:            protected void ensureHasNext() {
038:                if (hasNext() == false)
039:                    throw new NoSuchElementException();
040:            }
041:
042:            /**
043:                default next: throw an exception.
044:             */
045:            public Object next() {
046:                return noElements("empty NiceIterator");
047:            }
048:
049:            /**
050:                Utility method for this and other (sub)classes: raise the appropriate
051:                "no more elements" exception. I note that we raised the wrong exception
052:                in at least one case ...
053:            
054:                @param message the string to include in the exception
055:                @return never - but we have a return type to please the compiler
056:             */
057:            protected Object noElements(String message) {
058:                throw new NoSuchElementException(message);
059:            }
060:
061:            /**
062:                default remove: we have no elements, so we can't remove any.
063:             */
064:            public void remove() {
065:                throw new UnsupportedOperationException(
066:                        "remove not supported for this iterator");
067:            }
068:
069:            /**
070:                 Answer the next object, and remove it.
071:             */
072:            public Object removeNext() {
073:                Object result = next();
074:                remove();
075:                return result;
076:            }
077:
078:            /**
079:                concatenate two closable iterators.
080:             */
081:
082:            public static ExtendedIterator andThen(final Iterator a,
083:                    final Iterator b) {
084:                final List L = new ArrayList(2);
085:                L.add(b);
086:                return new NiceIterator() {
087:                    private int index = 0;
088:
089:                    private Iterator current = a;
090:
091:                    public boolean hasNext() {
092:                        while (current.hasNext() == false && index < L.size())
093:                            current = (Iterator) L.get(index++);
094:                        return current.hasNext();
095:                    }
096:
097:                    public Object next() {
098:                        return hasNext() ? current.next()
099:                                : noElements("concatenation");
100:                    }
101:
102:                    public void close() {
103:                        close(current);
104:                        for (int i = index; i < L.size(); i += 1)
105:                            close((Iterator) L.get(i));
106:                    }
107:
108:                    public void remove() {
109:                        current.remove();
110:                    }
111:
112:                    public ExtendedIterator andThen(ClosableIterator other) {
113:                        L.add(other);
114:                        return this ;
115:                    }
116:                };
117:            }
118:
119:            /**
120:                make a new iterator, which is us then the other chap.
121:             */
122:            public ExtendedIterator andThen(ClosableIterator other) {
123:                return andThen(this , other);
124:            }
125:
126:            /**
127:                make a new iterator, which is our elements that pass the filter
128:             */
129:            public ExtendedIterator filterKeep(Filter f) {
130:                return new FilterKeepIterator(f, this );
131:            }
132:
133:            /**
134:                make a new iterator, which is our elements that do not pass the filter
135:             */
136:            public ExtendedIterator filterDrop(final Filter f) {
137:                return new FilterDropIterator(f, this );
138:            }
139:
140:            /**
141:                make a new iterator which is the elementwise _map1_ of the base iterator.
142:             */
143:            public ExtendedIterator mapWith(Map1 map1) {
144:                return new Map1Iterator(map1, this );
145:            }
146:
147:            /**
148:                If <code>it</code> is a Closableiterator, close it. Abstracts away from
149:                tests [that were] scattered through the code.
150:             */
151:            public static void close(Iterator it) {
152:                if (it instanceof  ClosableIterator)
153:                    ((ClosableIterator) it).close();
154:            }
155:
156:            static final private NiceIterator emptyInstance = new NiceIterator();
157:
158:            /**
159:             * An iterator over no elements.
160:             * @return A class singleton which doesn't iterate.
161:             */
162:            static public ExtendedIterator emptyIterator() {
163:                return emptyInstance;
164:            }
165:
166:            /**
167:                Answer a list of the elements in order, consuming this iterator.
168:             */
169:            public List toList() {
170:                return asList(this );
171:            }
172:
173:            /**
174:                Answer a list of the elements in order, consuming this iterator.
175:             */
176:            public Set toSet() {
177:                return asSet(this );
178:            }
179:
180:            /**
181:                Answer a list of the elements of <code>it</code> in order, consuming this iterator.
182:                Canonical implementation of toSet().
183:             */
184:            public static Set asSet(ExtendedIterator it) {
185:                Set result = new HashSet();
186:                while (it.hasNext())
187:                    result.add(it.next());
188:                return result;
189:            }
190:
191:            /**
192:                Answer a list of the elements from <code>it</code>, in order, consuming
193:                that iterator. Canonical implementation of toList().
194:             */
195:            public static List asList(ExtendedIterator it) {
196:                List result = new ArrayList();
197:                while (it.hasNext())
198:                    result.add(it.next());
199:                return result;
200:            }
201:        }
202:
203:        /*
204:         (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
205:         All rights reserved.
206:
207:         Redistribution and use in source and binary forms, with or without
208:         modification, are permitted provided that the following conditions
209:         are met:
210:
211:         1. Redistributions of source code must retain the above copyright
212:         notice, this list of conditions and the following disclaimer.
213:
214:         2. Redistributions in binary form must reproduce the above copyright
215:         notice, this list of conditions and the following disclaimer in the
216:         documentation and/or other materials provided with the distribution.
217:
218:         3. The name of the author may not be used to endorse or promote products
219:         derived from this software without specific prior written permission.
220:
221:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
222:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
224:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
225:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
226:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
227:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
228:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
229:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
230:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
231:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.