| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.index; |
| 7 |
|
| 8 |
import org.h2.message.DbException; |
| 9 |
import org.h2.result.Row; |
| 10 |
import org.h2.result.SearchRow; |
| 11 |
|
| 12 |
/** |
| 13 |
* A cursor with at most one row. |
| 14 |
*/ |
| 15 |
public class SingleRowCursor implements Cursor { |
| 16 |
private Row row; |
| 17 |
private boolean end; |
| 18 |
|
| 19 |
/** |
| 20 |
* Create a new cursor. |
| 21 |
* |
| 22 |
* @param row - the single row (if null then cursor is empty) |
| 23 |
*/ |
| 24 |
public SingleRowCursor(Row row) { |
| 25 |
this.row = row; |
| 26 |
} |
| 27 |
|
| 28 |
@Override |
| 29 |
public Row get() { |
| 30 |
return row; |
| 31 |
} |
| 32 |
|
| 33 |
@Override |
| 34 |
public SearchRow getSearchRow() { |
| 35 |
return row; |
| 36 |
} |
| 37 |
|
| 38 |
@Override |
| 39 |
public boolean next() { |
| 40 |
if (row == null || end) { |
| 41 |
row = null; |
| 42 |
return false; |
| 43 |
} |
| 44 |
end = true; |
| 45 |
return true; |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
public boolean previous() { |
| 50 |
throw DbException.getInternalError(toString()); |
| 51 |
} |
| 52 |
|
| 53 |
} |