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