Package: ResultSetIterator
ResultSetIterator
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ResultSetIterator(ResultSet) |
|
|
|
|
|
||||||||||||||||||||
hasNext() |
|
|
|
|
|
||||||||||||||||||||
next() |
|
|
|
|
|
Coverage
1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.iteration;
19:
20: import cz.cvut.kbss.ontodriver.ResultSet;
21: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
22: import cz.cvut.kbss.ontodriver.exception.OntoDriverRuntimeException;
23:
24: import java.util.Iterator;
25: import java.util.NoSuchElementException;
26:
27: /**
28: * Iterator over a {@link ResultSet}.
29: * <p>
30: * Note that the methods wrap {@link OntoDriverException}s possibly thrown by the underlying result set in a {@link OntoDriverRuntimeException}
31: * in order to support the {@link Iterator} API.
32: */
33: public class ResultSetIterator implements Iterator<ResultRow> {
34:
35: private final ResultSet resultSet;
36:
37: public ResultSetIterator(ResultSet resultSet) {
38: this.resultSet = resultSet;
39: }
40:
41: @Override
42: public boolean hasNext() {
43: try {
44: return resultSet.hasNext();
45: } catch (OntoDriverException e) {
46: throw new ResultSetIterationException(e);
47: }
48: }
49:
50: @Override
51: public ResultRow next() {
52:• if (!hasNext()) {
53: throw new NoSuchElementException();
54: }
55: try {
56: resultSet.next();
57: return new DelegatingResultRow(resultSet);
58: } catch (OntoDriverException e) {
59: throw new ResultSetIterationException(e);
60: }
61: }
62: }