Skip to content
This repository was archived by the owner on Nov 19, 2019. It is now read-only.

Commit 201dc4c

Browse files
committed
added ExecutionResult to repo
1 parent 2304089 commit 201dc4c

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.neo4j.example.rest;
2+
3+
import java.util.Iterator;
4+
import java.util.List;
5+
import java.util.Map;
6+
7+
public interface ExecutionResult extends Iterable<List<Object>> {
8+
List<String> getColumns();
9+
10+
Iterator<List<Object>> iterator();
11+
12+
Iterator<Map<String,Object>> rowIterator();
13+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package org.neo4j.example.rest;
2+
3+
import java.util.*;
4+
5+
/**
6+
* Created by mh on 26.07.13.
7+
*/
8+
public class ExecutionResultImpl implements ExecutionResult {
9+
private final List<String> columns = new ArrayList<String>();
10+
private final List<List<Object>> data = new ArrayList<List<Object>>();
11+
private final int columnCount;
12+
13+
public ExecutionResultImpl(List<String> columns) {
14+
this.columns.addAll(columns);
15+
this.columnCount = columns.size();
16+
}
17+
void addRow(List<Object> row) {
18+
data.add(row);
19+
}
20+
void addRows(List<List<Object>> rows) {
21+
this.data.addAll(rows);
22+
}
23+
24+
@Override
25+
public List<String> getColumns() {
26+
return columns;
27+
}
28+
29+
@Override
30+
public Iterator<List<Object>> iterator() {
31+
return data.iterator();
32+
}
33+
34+
@Override
35+
public Iterator<Map<String,Object>> rowIterator() {
36+
return new RowIterator();
37+
}
38+
39+
private class RowIterator implements Iterator<Map<String, Object>> {
40+
final Iterator<List<Object>> it;
41+
42+
private RowIterator() {
43+
it = iterator();
44+
}
45+
46+
@Override
47+
public boolean hasNext() {
48+
return it.hasNext();
49+
}
50+
51+
@Override
52+
public Map<String, Object> next() {
53+
List<Object> rowData = it.next();
54+
Map<String,Object> row = new LinkedHashMap<String, Object>(columnCount);
55+
for (int col = 0; col < columnCount; col++) {
56+
row.put(columns.get(col),rowData.get(col));
57+
}
58+
return row;
59+
}
60+
61+
@Override
62+
public void remove() {
63+
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)