KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdql > ResultBindingIterator


1 /*
2  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  * [See end of file]
5  */

6
7 package com.hp.hpl.jena.rdql;
8
9 import java.util.Iterator JavaDoc;
10
11
12
13 /** Iterates over the variable names.
14  * Has extra operations to access the current variable value.
15  */

16
17 public class ResultBindingIterator implements Iterator JavaDoc
18 {
19     boolean active ;
20     boolean doneThisOne ;
21     ResultBindingImpl binding ;
22     int i ;
23     
24     ResultBindingIterator(ResultBindingImpl _binding)
25     {
26         binding = _binding ;
27         // -1 indicates not started
28
i = -1 ;
29         // Set true to make it move on on first use.
30
doneThisOne = true ;
31         active = true ;
32     }
33     
34     public boolean hasNext()
35     {
36         if ( doneThisOne )
37             advance() ;
38         return active ;
39     }
40     
41     public Object JavaDoc next()
42     {
43         advance() ;
44         doneThisOne = true ;
45         return binding.varNames.get(i) ;
46     }
47     
48     public String JavaDoc varName()
49     {
50         if ( ! active )
51             return null ;
52         return (String JavaDoc)binding.varNames.get(i) ;
53     }
54
55 // public Value value()
56
// {
57
// if ( ! active )
58
// return null ;
59
// return ResultBindingImpl.convert(binding.values.get(i)) ;
60
// }
61

62     public void remove() { throw new java.lang.UnsupportedOperationException JavaDoc("ResultsBindingIterator.remove") ; }
63     
64     private boolean advance()
65     {
66         if ( ! active )
67             return false ;
68         // Have not yielded the current value (no next called).
69
if ( ! doneThisOne )
70             return true ;
71         i++ ;
72         if ( i >= binding.varNames.size() )
73         {
74             i = -1 ;
75             binding = binding.parent ;
76             doneThisOne = true ;
77             if ( binding == null )
78             {
79                 active = false ;
80                 return active ;
81             }
82             // Moved to parent but it may itself be empty.
83
return advance() ;
84         }
85         doneThisOne = false ;
86         //active = true ;
87
return active ;
88     }
89 }
90 /*
91  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
92  * All rights reserved.
93  *
94  * Redistribution and use in source and binary forms, with or without
95  * modification, are permitted provided that the following conditions
96  * are met:
97  * 1. Redistributions of source code must retain the above copyright
98  * notice, this list of conditions and the following disclaimer.
99  * 2. Redistributions in binary form must reproduce the above copyright
100  * notice, this list of conditions and the following disclaimer in the
101  * documentation and/or other materials provided with the distribution.
102  * 3. The name of the author may not be used to endorse or promote products
103  * derived from this software without specific prior written permission.
104  *
105  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
106  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
107  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
108  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
109  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
110  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
111  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
112  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
113  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
114  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
115  */
Popular Tags