|
27 | 27 | * Cursor entity that represents the result of a AQL query. |
28 | 28 | * |
29 | 29 | * @author tamtam180 - kirscheless at gmail.com |
| 30 | + * @author mrbatista |
30 | 31 | * |
31 | 32 | */ |
32 | 33 | public class CursorEntity<T> extends BaseEntity implements Iterable<T> { |
33 | 34 |
|
34 | | - /** |
35 | | - * True if the cursor has more results. |
36 | | - */ |
37 | | - boolean hasMore; |
38 | | - |
39 | | - /** |
40 | | - * The amount of results in the cursor |
41 | | - */ |
42 | | - int count = -1; |
43 | | - |
44 | | - /** |
45 | | - * The number of results before the final LIMIT |
46 | | - */ |
47 | | - int fullCount = -1; |
48 | | - |
49 | | - /** |
50 | | - * The cursor id |
51 | | - */ |
52 | | - long cursorId = -1; |
53 | | - |
54 | | - /** |
55 | | - * A list of bind variables returned by the query |
56 | | - */ |
57 | | - List<String> bindVars; |
58 | | - |
59 | | - /** |
60 | | - * A list of extra data returned by the query |
61 | | - */ |
62 | | - Map<String, Object> extra; |
63 | | - |
64 | | - /** |
65 | | - * A list of objects containing the results |
66 | | - */ |
67 | | - List<? extends T> results; |
68 | | - |
69 | | - public Iterator<T> iterator() { |
70 | | - return (Iterator<T>) CollectionUtils.safetyIterator(results); |
71 | | - } |
72 | | - |
73 | | - /** |
74 | | - * The size of the cursor results. |
75 | | - * |
76 | | - * @return int |
77 | | - */ |
78 | | - public int size() { |
79 | | - if (results == null) { |
80 | | - return 0; |
81 | | - } |
82 | | - return results.size(); |
83 | | - } |
84 | | - |
85 | | - /** |
86 | | - * Returns the cursor element at position *index* |
87 | | - * |
88 | | - * @param index |
89 | | - * @return Object |
90 | | - */ |
91 | | - public T get(int index) { |
92 | | - rangeCheck(index); |
93 | | - return results.get(index); |
94 | | - } |
95 | | - |
96 | | - private void rangeCheck(int index) { |
97 | | - int size = size(); |
98 | | - if (index < 0 || index >= size) { |
99 | | - throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size); |
100 | | - } |
101 | | - } |
102 | | - |
103 | | - public List<? extends T> getResults() { |
104 | | - return results; |
105 | | - } |
106 | | - |
107 | | - public T getUniqueResult() { |
108 | | - int size = size(); |
109 | | - if (size == 0) return null; |
110 | | - if (size > 1) throw new NonUniqueResultException(size); |
111 | | - return get(0); |
112 | | - } |
113 | | - |
114 | | - public boolean isHasMore() { |
115 | | - return hasMore; |
116 | | - } |
117 | | - |
118 | | - public boolean hasMore() { |
119 | | - return hasMore; |
120 | | - } |
121 | | - |
122 | | - public int getFullCount() { |
123 | | - return fullCount; |
124 | | - } |
125 | | - |
126 | | - public int getCount() { |
127 | | - return count; |
128 | | - } |
129 | | - |
130 | | - public long getCursorId() { |
131 | | - return cursorId; |
132 | | - } |
133 | | - |
134 | | - public List<String> getBindVars() { |
135 | | - return bindVars; |
136 | | - } |
137 | | - |
138 | | - public Map<String, Object> getExtra() { |
139 | | - return extra; |
140 | | - } |
141 | | - |
142 | | - public void setResults(List<T> results) { |
143 | | - this.results = results; |
144 | | - } |
145 | | - |
146 | | - public void setHasMore(boolean hasMore) { |
147 | | - this.hasMore = hasMore; |
148 | | - } |
149 | | - |
150 | | - public void setFullCount(int count) { |
151 | | - this.fullCount = count; |
152 | | - } |
153 | | - |
154 | | - public void setCount(int count) { |
155 | | - this.count = count; |
156 | | - } |
157 | | - |
158 | | - public void setCursorId(long cursorId) { |
159 | | - this.cursorId = cursorId; |
160 | | - } |
161 | | - |
162 | | - public void setBindVars(List<String> bindVars) { |
163 | | - this.bindVars = bindVars; |
164 | | - } |
165 | | - |
166 | | - public void setExtra(Map<String, Object> extra) { |
167 | | - this.extra = extra; |
168 | | - } |
169 | | - |
| 35 | + /** |
| 36 | + * True if the cursor has more results. |
| 37 | + */ |
| 38 | + boolean hasMore; |
| 39 | + |
| 40 | + /** |
| 41 | + * The amount of results in the cursor |
| 42 | + */ |
| 43 | + int count = -1; |
| 44 | + |
| 45 | + /** |
| 46 | + * The number of results before the final LIMIT |
| 47 | + */ |
| 48 | + int fullCount = -1; |
| 49 | + |
| 50 | + /** |
| 51 | + * The cursor id |
| 52 | + */ |
| 53 | + long cursorId = -1; |
| 54 | + |
| 55 | + /** |
| 56 | + * A list of bind variables returned by the query |
| 57 | + */ |
| 58 | + List<String> bindVars; |
| 59 | + |
| 60 | + /** |
| 61 | + * A list of extra data returned by the query |
| 62 | + */ |
| 63 | + Map<String, Object> extra; |
| 64 | + |
| 65 | + /** |
| 66 | + * A list of objects containing the results |
| 67 | + */ |
| 68 | + List<? extends T> results; |
| 69 | + |
| 70 | + @Override |
| 71 | + public Iterator<T> iterator() { |
| 72 | + return (Iterator<T>) CollectionUtils.safetyIterator(results); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * The size of the cursor results. |
| 77 | + * |
| 78 | + * @return int |
| 79 | + */ |
| 80 | + public int size() { |
| 81 | + if (results == null) { |
| 82 | + return 0; |
| 83 | + } |
| 84 | + return results.size(); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Returns the cursor element at position *index* |
| 89 | + * |
| 90 | + * @param index |
| 91 | + * @return Object |
| 92 | + */ |
| 93 | + public T get(int index) { |
| 94 | + rangeCheck(index); |
| 95 | + return results.get(index); |
| 96 | + } |
| 97 | + |
| 98 | + private void rangeCheck(int index) { |
| 99 | + int size = size(); |
| 100 | + if (index < 0 || index >= size) { |
| 101 | + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + public List<? extends T> getResults() { |
| 106 | + return results; |
| 107 | + } |
| 108 | + |
| 109 | + public T getUniqueResult() { |
| 110 | + int size = size(); |
| 111 | + if (size == 0) { |
| 112 | + return null; |
| 113 | + } |
| 114 | + if (size > 1) { |
| 115 | + throw new NonUniqueResultException(size); |
| 116 | + } |
| 117 | + return get(0); |
| 118 | + } |
| 119 | + |
| 120 | + public boolean isHasMore() { |
| 121 | + return hasMore; |
| 122 | + } |
| 123 | + |
| 124 | + public boolean hasMore() { |
| 125 | + return hasMore; |
| 126 | + } |
| 127 | + |
| 128 | + public int getFullCount() { |
| 129 | + return fullCount; |
| 130 | + } |
| 131 | + |
| 132 | + public int getCount() { |
| 133 | + return count; |
| 134 | + } |
| 135 | + |
| 136 | + public long getCursorId() { |
| 137 | + return cursorId; |
| 138 | + } |
| 139 | + |
| 140 | + public List<String> getBindVars() { |
| 141 | + return bindVars; |
| 142 | + } |
| 143 | + |
| 144 | + public Map<String, Object> getExtra() { |
| 145 | + return extra; |
| 146 | + } |
| 147 | + |
| 148 | + public void setResults(List<T> results) { |
| 149 | + this.results = results; |
| 150 | + } |
| 151 | + |
| 152 | + public void setHasMore(boolean hasMore) { |
| 153 | + this.hasMore = hasMore; |
| 154 | + } |
| 155 | + |
| 156 | + public void setFullCount(int count) { |
| 157 | + this.fullCount = count; |
| 158 | + } |
| 159 | + |
| 160 | + public void setCount(int count) { |
| 161 | + this.count = count; |
| 162 | + } |
| 163 | + |
| 164 | + public void setCursorId(long cursorId) { |
| 165 | + this.cursorId = cursorId; |
| 166 | + } |
| 167 | + |
| 168 | + public void setBindVars(List<String> bindVars) { |
| 169 | + this.bindVars = bindVars; |
| 170 | + } |
| 171 | + |
| 172 | + public void setExtra(Map<String, Object> extra) { |
| 173 | + this.extra = extra; |
| 174 | + } |
| 175 | + |
170 | 176 | } |
0 commit comments