KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > search > AbstractResultSetRowIterator


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.search;
18
19 import org.alfresco.service.cmr.search.ResultSet;
20 import org.alfresco.service.cmr.search.ResultSetRow;
21
22
23 /**
24  * Iterate over the rows in a ResultSet
25  *
26  * @author andyh
27  *
28  */

29 public abstract class AbstractResultSetRowIterator implements ResultSetRowIterator
30 {
31     /**
32      * The result set
33      */

34     private ResultSet resultSet;
35
36     /**
37      * The current position
38      */

39     private int position = -1;
40
41     /**
42      * The maximum position
43      */

44     private int max;
45
46     /**
47      * Create an iterator over the result set. Follows stadard ListIterator
48      * conventions
49      *
50      * @param resultSet
51      */

52     public AbstractResultSetRowIterator(ResultSet resultSet)
53     {
54         super();
55         this.resultSet = resultSet;
56         this.max = resultSet.length();
57     }
58
59     
60     
61     public ResultSet getResultSet()
62     {
63         return resultSet;
64     }
65     
66
67
68
69     /*
70      * ListIterator implementation
71      */

72     public boolean hasNext()
73     {
74         return position < (max - 1);
75     }
76
77     public boolean allowsReverse()
78     {
79         return true;
80     }
81
82     public boolean hasPrevious()
83     {
84         return position > 0;
85     }
86
87     abstract public ResultSetRow next();
88     
89     protected int moveToNextPosition()
90     {
91         return ++position;
92     }
93
94     abstract public ResultSetRow previous();
95     
96     protected int moveToPreviousPosition()
97     {
98         return --position;
99     }
100
101     public int nextIndex()
102     {
103         return position + 1;
104     }
105
106     public int previousIndex()
107     {
108         return position - 1;
109     }
110
111     /*
112      * Mutation is not supported
113      */

114
115     public void remove()
116     {
117         // TODO Auto-generated method stub
118
throw new UnsupportedOperationException JavaDoc();
119     }
120
121     public void set(ResultSetRow o)
122     {
123         // TODO Auto-generated method stub
124
throw new UnsupportedOperationException JavaDoc();
125     }
126
127     public void add(ResultSetRow o)
128     {
129         // TODO Auto-generated method stub
130
throw new UnsupportedOperationException JavaDoc();
131     }
132
133 }
134
Popular Tags