@ -40,6 +40,7 @@ import com.mongodb.DBObject;
@@ -40,6 +40,7 @@ import com.mongodb.DBObject;
* @author Thomas Darimont
* @author Oliver Gierke
* @author Gustavo de Geus
* @author Christoph Strobl
* @since 1 . 3
* /
public class GroupOperation implements FieldsExposingAggregationOperation {
@ -312,23 +313,47 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
@@ -312,23 +313,47 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
* Generates an { @link GroupOperationBuilder } for an { @code $stdDevSamp } - expression that for the given
* field - reference .
*
* @param reference
* @return
* @param reference must not be { @literal null } .
* @return never { @literal null } .
* @since 1 . 10
* /
public GroupOperationBuilder stdDevSamp ( String reference ) {
return newBuilder ( GroupOps . STD_DEV_SAMP , reference , null ) ;
}
/ * *
* Generates an { @link GroupOperationBuilder } for an { @code $stdDevSamp } - expression that for the given { @link AggregationExpression } .
*
* @param expr must not be { @literal null } .
* @return never { @literal null } .
* @since 1 . 10
* /
public GroupOperationBuilder stdDevSamp ( AggregationExpression expr ) {
return newBuilder ( GroupOps . STD_DEV_SAMP , null , expr ) ;
}
/ * *
* Generates an { @link GroupOperationBuilder } for an { @code $stdDevPop } - expression that for the given field - reference .
*
* @param reference
* @return
* @param reference must not be { @literal null } .
* @return never { @literal null } .
* @since 1 . 10
* /
public GroupOperationBuilder stdDevPop ( String reference ) {
return newBuilder ( GroupOps . STD_DEV_POP , reference , null ) ;
}
/ * *
* Generates an { @link GroupOperationBuilder } for an { @code $stdDevPop } - expression that for the given { @link AggregationExpression } .
*
* @param expr must not be { @literal null } .
* @return never { @literal null } .
* @since 1 . 10
* /
public GroupOperationBuilder stdDevPop ( AggregationExpression expr ) {
return newBuilder ( GroupOps . STD_DEV_POP , null , expr ) ;
}
private GroupOperationBuilder newBuilder ( Keyword keyword , String reference , Object value ) {
return new GroupOperationBuilder ( this , new Operation ( keyword , null , reference , value ) ) ;
}
@ -393,21 +418,18 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
@@ -393,21 +418,18 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
private static enum GroupOps implements Keyword {
SUM , LAST , FIRST , PUSH , AVG , MIN , MAX , ADD_TO_SET , COUNT , STD_DEV_SAMP , STD_DEV_POP ;
@Override
public String toString ( ) {
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" ) ;
String [ ] parts = name ( ) . split ( "_" ) ;
private String mongoOperator ;
StringBuilder builder = new StringBuilder ( ) ;
GroupOps ( String mongoOperator ) {
this . mongoOperator = mongoOperator ;
}
for ( String part : parts ) {
String lowerCase = part . toLowerCase ( Locale . US ) ;
builder . append ( builder . length ( ) = = 0 ? lowerCase : StringUtils . capitalize ( lowerCase ) ) ;
}
return "$" + builder . toString ( ) ;
@Override
public String toString ( ) {
return mongoOperator ;
}
}