Skip to content

Commit f275aaa

Browse files
DATAMONGO-1327 - Polishing.
Just added overloads for stdDevSamp and stdDevPop taking AggregationExpression and updated the doc. Also replaced String operation based MongoDB operation building by using operators directly. Original Pull Request: #360
1 parent 5d2faef commit f275aaa

File tree

1 file changed

+36
-15
lines changed
  • spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation

1 file changed

+36
-15
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/GroupOperation.java

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -319,23 +319,47 @@ public GroupOperationBuilder max(AggregationExpression expr) {
319319
* Generates an {@link GroupOperationBuilder} for an {@code $stdDevSamp}-expression that for the given
320320
* field-reference.
321321
*
322-
* @param reference
323-
* @return
322+
* @param reference must not be {@literal null}.
323+
* @return never {@literal null}.
324+
* @since 1.10
324325
*/
325326
public GroupOperationBuilder stdDevSamp(String reference) {
326327
return newBuilder(GroupOps.STD_DEV_SAMP, reference, null);
327328
}
328329

330+
/**
331+
* Generates an {@link GroupOperationBuilder} for an {@code $stdDevSamp}-expression that for the given {@link AggregationExpression}.
332+
*
333+
* @param expr must not be {@literal null}.
334+
* @return never {@literal null}.
335+
* @since 1.10
336+
*/
337+
public GroupOperationBuilder stdDevSamp(AggregationExpression expr) {
338+
return newBuilder(GroupOps.STD_DEV_SAMP, null, expr);
339+
}
340+
329341
/**
330342
* Generates an {@link GroupOperationBuilder} for an {@code $stdDevPop}-expression that for the given field-reference.
331343
*
332-
* @param reference
333-
* @return
344+
* @param reference must not be {@literal null}.
345+
* @return never {@literal null}.
346+
* @since 1.10
334347
*/
335348
public GroupOperationBuilder stdDevPop(String reference) {
336349
return newBuilder(GroupOps.STD_DEV_POP, reference, null);
337350
}
338351

352+
/**
353+
* Generates an {@link GroupOperationBuilder} for an {@code $stdDevPop}-expression that for the given {@link AggregationExpression}.
354+
*
355+
* @param expr must not be {@literal null}.
356+
* @return never {@literal null}.
357+
* @since 1.10
358+
*/
359+
public GroupOperationBuilder stdDevPop(AggregationExpression expr) {
360+
return newBuilder(GroupOps.STD_DEV_POP, null, expr);
361+
}
362+
339363
private GroupOperationBuilder newBuilder(Keyword keyword, String reference, Object value) {
340364
return new GroupOperationBuilder(this, new Operation(keyword, null, reference, value));
341365
}
@@ -400,21 +424,18 @@ interface Keyword {
400424

401425
private static enum GroupOps implements Keyword {
402426

403-
SUM, LAST, FIRST, PUSH, AVG, MIN, MAX, ADD_TO_SET, COUNT, STD_DEV_SAMP, STD_DEV_POP;
404-
405-
@Override
406-
public String toString() {
427+
SUM("$sum"), LAST("$last"), FIRST("$first"), PUSH("$push"), AVG("$avg"), MIN("$min"), MAX("$max"), ADD_TO_SET("$addToSet"), STD_DEV_POP("$stdDevPop"), STD_DEV_SAMP("$stdDevSamp");
407428

408-
String[] parts = name().split("_");
429+
private String mongoOperator;
409430

410-
StringBuilder builder = new StringBuilder();
431+
GroupOps(String mongoOperator) {
432+
this.mongoOperator = mongoOperator;
433+
}
411434

412-
for (String part : parts) {
413-
String lowerCase = part.toLowerCase(Locale.US);
414-
builder.append(builder.length() == 0 ? lowerCase : StringUtils.capitalize(lowerCase));
415-
}
416435

417-
return "$" + builder.toString();
436+
@Override
437+
public String toString() {
438+
return mongoOperator;
418439
}
419440
}
420441

0 commit comments

Comments
 (0)