Skip to content

Commit db43ef5

Browse files
committed
typed GeoResult converters
1 parent 6583c2c commit db43ef5

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/main/java/com/arangodb/springframework/repository/query/AbstractArangoQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ private Object convertResult(final ArangoCursor<?> result, final ArangoParameter
200200
}
201201
return (Integer) result.next() > 0;
202202
}
203-
final ArangoResultConverter resultConverter = new ArangoResultConverter(accessor, result, operations, domainClass);
203+
final ArangoResultConverter<?> resultConverter = new ArangoResultConverter<>(accessor, result, operations, domainClass);
204204
return resultConverter.convertResult(method.getReturnType().getType());
205205
}
206206

src/main/java/com/arangodb/springframework/repository/query/ArangoResultConverter.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@
5353
* @author Mark Vollmary
5454
* @author Christian Lechner
5555
*/
56-
public class ArangoResultConverter {
56+
public class ArangoResultConverter<T> {
5757

5858
private final static String MISSING_FULL_COUNT = "Query result does not contain the full result count! "
5959
+ "The most likely cause is a forgotten LIMIT clause in the query.";
6060

6161
private final ArangoParameterAccessor accessor;
6262
private final ArangoCursor<?> result;
6363
private final ArangoOperations operations;
64-
private final Class<?> domainClass;
64+
private final Class<T> domainClass;
6565

6666

6767
/**
@@ -71,7 +71,7 @@ public class ArangoResultConverter {
7171
* @param domainClass class type of documents
7272
*/
7373
public ArangoResultConverter(final ArangoParameterAccessor accessor, final ArangoCursor<?> result,
74-
final ArangoOperations operations, final Class<?> domainClass) {
74+
final ArangoOperations operations, final Class<T> domainClass) {
7575
this.accessor = accessor;
7676
this.result = result;
7777
this.operations = operations;
@@ -132,22 +132,21 @@ private Set<?> buildSet(final ArangoCursor<?> cursor) {
132132
* @param cursor query result from driver
133133
* @return GeoResult object
134134
*/
135-
private GeoResult<?> buildGeoResult(final ArangoCursor<?> cursor) {
135+
private GeoResult<T> buildGeoResult(final ArangoCursor<TxJsonNode> cursor) {
136136
return buildGeoResult(cursor.next());
137137
}
138138

139139
/**
140140
* Construct a GeoResult from the given object
141141
*
142-
* @param object object representing one document in the result
142+
* @param data object representing one document in the result
143143
* @return GeoResult object
144144
*/
145-
private GeoResult<?> buildGeoResult(final Object object) {
146-
final TxJsonNode data = (TxJsonNode) object;
145+
private GeoResult<T> buildGeoResult(final TxJsonNode data) {
147146
final JsonNode slice = data.value();
148147
final JsonNode distSlice = slice.get("_distance");
149148
final Double distanceInMeters = distSlice.isDouble() ? distSlice.doubleValue() : null;
150-
final Object entity = operations.getConverter().read(domainClass, data);
149+
final T entity = operations.getConverter().read(domainClass, data);
151150
final Distance distance = new Distance(distanceInMeters / 1000, Metrics.KILOMETERS);
152151
return new GeoResult<>(entity, distance);
153152
}
@@ -158,11 +157,10 @@ private GeoResult<?> buildGeoResult(final Object object) {
158157
* @param cursor ArangoCursor containing query results
159158
* @return GeoResults object with all results
160159
*/
161-
@SuppressWarnings({"rawtypes", "unchecked"})
162-
private GeoResults<?> buildGeoResults(final ArangoCursor<?> cursor) {
163-
final List<GeoResult<?>> list = new LinkedList<>();
160+
private GeoResults<T> buildGeoResults(final ArangoCursor<TxJsonNode> cursor) {
161+
final List<GeoResult<T>> list = new LinkedList<>();
164162
cursor.forEachRemaining(o -> list.add(buildGeoResult(o)));
165-
return new GeoResults(list);
163+
return new GeoResults<>(list);
166164
}
167165

168166
public Optional<?> convertOptional() {
@@ -186,17 +184,20 @@ public ArangoCursor<?> convertArangoCursor() {
186184
return result;
187185
}
188186

189-
public GeoResult<?> convertGeoResult() {
190-
return buildGeoResult(result);
187+
@SuppressWarnings("unchecked")
188+
public GeoResult<T> convertGeoResult() {
189+
return buildGeoResult((ArangoCursor<TxJsonNode>) result);
191190
}
192191

193-
public GeoResults<?> convertGeoResults() {
194-
return buildGeoResults(result);
192+
@SuppressWarnings("unchecked")
193+
public GeoResults<T> convertGeoResults() {
194+
return buildGeoResults((ArangoCursor<TxJsonNode>) result);
195195
}
196196

197-
public GeoPage<?> convertGeoPage() {
197+
@SuppressWarnings("unchecked")
198+
public GeoPage<T> convertGeoPage() {
198199
Assert.notNull(result.getStats().getFullCount(), MISSING_FULL_COUNT);
199-
return new GeoPage<>(buildGeoResults(result), accessor.getPageable(), ((Number) result.getStats().getFullCount()).longValue());
200+
return new GeoPage<>(buildGeoResults((ArangoCursor<TxJsonNode>) result), accessor.getPageable(), ((Number) result.getStats().getFullCount()).longValue());
200201
}
201202

202203
public Object convertArray() {

0 commit comments

Comments
 (0)