File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\index\NonUniqueHashCursor.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.index;
8
9 import java.util.ArrayList;
10 import org.h2.engine.Session;
11 import org.h2.result.Row;
12 import org.h2.result.SearchRow;
13 import org.h2.table.RegularTable;
14
15 /**
16 * Cursor implementation for non-unique hash index
17 *
18 * @author Sergi Vladykin
19 */
20 public class NonUniqueHashCursor implements Cursor {
21
22 private final Session session;
23 private final ArrayList<Long> positions;
24 private final RegularTable tableData;
25
26 private int index = -1;
27
28 public NonUniqueHashCursor(Session session, RegularTable tableData, ArrayList<Long> positions) {
29 this.session = session;
30 this.tableData = tableData;
31 this.positions = positions;
32 }
33
34 public Row get() {
35 if (index < 0 || index >= positions.size()) {
36 return null;
37 }
38 return tableData.getRow(session, positions.get(index));
39 }
40
41 public SearchRow getSearchRow() {
42 return get();
43 }
44
45 public boolean next() {
46 return positions != null && ++index < positions.size();
47 }
48
49 public boolean previous() {
50 return positions != null && --index >= 0;
51 }
52
53 }
54