KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > util > iterator > LateBindingIterator


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $Id: LateBindingIterator.java,v 1.3 2005/02/21 12:19:15 andy_seaborne Exp $
28  *
29  *
30  * LateBindingIterator.java
31  *
32  * Created on June 16, 2001, 8:19 PM
33  */

34
35 package com.hp.hpl.jena.util.iterator;
36 import java.util.Iterator JavaDoc ;
37 /** An Iterator that is created lazily.
38  * The sequence to be defined is defined by
39  * the subclass's definition of create().
40  * This is only called on the first call to
41  * <CODE>hasNext()</CODE> or <CODE>next()</CODE>.
42  * This allows an Iterator to be passed to some other
43  * code, while delaying the evaluation of what actually
44  * is going to be iterated over.
45  * @author jjc
46  * @version Release='$Name: $' Revision='$Revision: 1.3 $' Date='$Date: 2005/02/21 12:19:15 $'
47  */

48 abstract public class LateBindingIterator implements Iterator JavaDoc {
49
50     private Iterator JavaDoc it;
51     
52     /** An Iterator that is created lazily.
53      * The sequence to be defined is defined by
54      * a subclass's instantiation of create().
55      * This is only called on the first call to
56      * <CODE>hasNext()</CODE> or <CODE>next()</CODE>.
57  */

58     public LateBindingIterator() {
59     }
60
61     public boolean hasNext() {
62         lazy();
63         return it.hasNext();
64     }
65     
66     public Object JavaDoc next() {
67         lazy();
68         return it.next();
69     }
70     
71     public void remove() {
72         lazy();
73         it.remove();
74     }
75     
76     private void lazy() {
77         if ( it == null )
78             it = create();
79     }
80 /** The subclass must define this to return
81  * the Iterator to invoke. This method will be
82  * called at most once, on the first call to
83  * <CODE>next()</CODE> or <CODE>hasNext()</CODE>.
84  * From then on, all calls to this will be passed
85  * through to the returned Iterator.
86  * @return The parent iterator defining the sequence.
87  */

88     public abstract Iterator JavaDoc create();
89     
90 }
91
Popular Tags