1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.mavibot.btree; 21 22 23 import java.io.IOException; 24 import java.util.NoSuchElementException; 25 26 import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException; 27 28 29 /** 30 * A Cursor which is used when we have no element to return 31 * <p> 32 * 33 * @param <K> The type for the Key 34 * @param <V> The type for the stored value 35 * 36 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 37 */ 38 public class EmptyTupleCursor<K, V> extends TupleCursor<K, V> 39 { 40 private long revision; 41 private long creationDate; 42 43 /** 44 * Creates a new instance of Cursor, starting on a page at a given position. 45 * 46 * @param transaction The transaction this operation is protected by 47 * @param stack The stack of parent's from root to this page 48 */ 49 public EmptyTupleCursor( long revision ) 50 { 51 super(); 52 53 this.revision = revision; 54 creationDate = System.currentTimeMillis(); 55 } 56 57 58 /** 59 * Change the position in the current cursor to set it after the last key 60 */ 61 public void afterLast() throws IOException 62 { 63 } 64 65 66 /** 67 * Change the position in the current cursor before the first key 68 */ 69 public void beforeFirst() throws IOException 70 { 71 } 72 73 74 /** 75 * Tells if the cursor can return a next element 76 * 77 * @return true if there are some more elements 78 * @throws IOException 79 * @throws EndOfFileExceededException 80 */ 81 public boolean hasNext() throws EndOfFileExceededException, IOException 82 { 83 return false; 84 } 85 86 87 /** 88 * Find the next key/value 89 * 90 * @return A Tuple containing the found key and value 91 * @throws IOException 92 * @throws EndOfFileExceededException 93 */ 94 public Tuple<K, V> next() throws EndOfFileExceededException, IOException 95 { 96 throw new NoSuchElementException( "No tuple present" ); 97 } 98 99 100 /** 101 * Get the next non-duplicate key. 102 * If the BTree contains : 103 * 104 * <ul> 105 * <li><1,0></li> 106 * <li><1,1></li> 107 * <li><1,2></li> 108 * <li><2,0></li> 109 * <li><2,1></li> 110 * </ul> 111 * 112 * and cursor is present at <1,1> then the returned tuple will be <2,0> (not <1,2>) 113 * 114 * @return A Tuple containing the found key and value 115 * @throws EndOfFileExceededException 116 * @throws IOException 117 */ 118 public Tuple<K, V> nextKey() throws EndOfFileExceededException, IOException 119 { 120 // This is the end : no more value 121 throw new NoSuchElementException( "No more tuples present" ); 122 } 123 124 125 /** 126 * Tells if the cursor can return a next key 127 * 128 * @return true if there are some more keys 129 * @throws IOException 130 * @throws EndOfFileExceededException 131 */ 132 public boolean hasNextKey() throws EndOfFileExceededException, IOException 133 { 134 return false; 135 } 136 137 138 /** 139 * Tells if the cursor can return a previous element 140 * 141 * @return true if there are some more elements 142 * @throws IOException 143 * @throws EndOfFileExceededException 144 */ 145 public boolean hasPrev() throws EndOfFileExceededException, IOException 146 { 147 return false; 148 } 149 150 151 /** 152 * Find the previous key/value 153 * 154 * @return A Tuple containing the found key and value 155 * @throws IOException 156 * @throws EndOfFileExceededException 157 */ 158 public Tuple<K, V> prev() throws EndOfFileExceededException, IOException 159 { 160 throw new NoSuchElementException( "No more tuple present" ); 161 } 162 163 164 /** 165 * Get the previous non-duplicate key. 166 * If the BTree contains : 167 * 168 * <ul> 169 * <li><1,0></li> 170 * <li><1,1></li> 171 * <li><1,2></li> 172 * <li><2,0></li> 173 * <li><2,1></li> 174 * </ul> 175 * 176 * and cursor is present at <2,1> then the returned tuple will be <1,0> (not <2,0>) 177 * 178 * @return A Tuple containing the found key and value 179 * @throws EndOfFileExceededException 180 * @throws IOException 181 */ 182 public Tuple<K, V> prevKey() throws EndOfFileExceededException, IOException 183 { 184 throw new NoSuchElementException( "No more tuples present" ); 185 } 186 187 188 /** 189 * Tells if the cursor can return a previous key 190 * 191 * @return true if there are some more keys 192 * @throws IOException 193 * @throws EndOfFileExceededException 194 */ 195 public boolean hasPrevKey() throws EndOfFileExceededException, IOException 196 { 197 return false; 198 } 199 200 201 /** 202 * {@inheritDoc} 203 */ 204 public void close() 205 { 206 } 207 208 209 /** 210 * Get the creation date 211 * @return The creation date for this cursor 212 */ 213 public long getCreationDate() 214 { 215 return creationDate; 216 } 217 218 219 /** 220 * Get the current revision 221 * 222 * @return The revision this cursor is based on 223 */ 224 public long getRevision() 225 { 226 return revision; 227 } 228 229 230 public String toString() 231 { 232 return "EmptyTupleCursor"; 233 } 234 }