Skip to content

Commit c9c5fe6

Browse files
DATAMONGO-1552 - Polishing.
Updated doc, removed whitespaces, minor method wording changes. Original Pull Request: #426
1 parent d250f88 commit c9c5fe6

File tree

9 files changed

+88
-104
lines changed

9 files changed

+88
-104
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ public static OutOperation out(String outCollectionName) {
424424
*
425425
* @param groupByField must not be {@literal null} or empty.
426426
* @return
427+
* @since 1.10
427428
*/
428429
public static BucketOperation bucket(String groupByField) {
429430
return new BucketOperation(field(groupByField));
@@ -434,6 +435,7 @@ public static BucketOperation bucket(String groupByField) {
434435
*
435436
* @param groupByExpression must not be {@literal null}.
436437
* @return
438+
* @since 1.10
437439
*/
438440
public static BucketOperation bucket(AggregationExpression groupByExpression) {
439441
return new BucketOperation(groupByExpression);
@@ -445,6 +447,7 @@ public static BucketOperation bucket(AggregationExpression groupByExpression) {
445447
* @param groupByField must not be {@literal null} or empty.
446448
* @param buckets number of buckets, must be a positive integer.
447449
* @return
450+
* @since 1.10
448451
*/
449452
public static BucketAutoOperation bucketAuto(String groupByField, int buckets) {
450453
return new BucketAutoOperation(field(groupByField), buckets);
@@ -456,6 +459,7 @@ public static BucketAutoOperation bucketAuto(String groupByField, int buckets) {
456459
* @param groupByExpression must not be {@literal null}.
457460
* @param buckets number of buckets, must be a positive integer.
458461
* @return
462+
* @since 1.10
459463
*/
460464
public static BucketAutoOperation bucketAuto(AggregationExpression groupByExpression, int buckets) {
461465
return new BucketAutoOperation(groupByExpression, buckets);
@@ -465,6 +469,7 @@ public static BucketAutoOperation bucketAuto(AggregationExpression groupByExpres
465469
* Creates a new {@link FacetOperation}.
466470
*
467471
* @return
472+
* @since 1.10
468473
*/
469474
public static FacetOperation facet() {
470475
return FacetOperation.EMPTY;
@@ -475,6 +480,7 @@ public static FacetOperation facet() {
475480
*
476481
* @param aggregationOperations the sub-pipeline, must not be {@literal null}.
477482
* @return
483+
* @since 1.10
478484
*/
479485
public static FacetOperationBuilder facet(AggregationOperation... aggregationOperations) {
480486
return facet().and(aggregationOperations);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
/**
3030
* Rendering support for {@link AggregationOperation} into a {@link List} of {@link com.mongodb.DBObject}.
31-
*
31+
*
3232
* @author Mark Paluch
3333
* @author Christoph Strobl
3434
* @since 1.10
@@ -40,7 +40,7 @@ class AggregationOperationRenderer {
4040
/**
4141
* Render a {@link List} of {@link AggregationOperation} given {@link AggregationOperationContext} into their
4242
* {@link DBObject} representation.
43-
*
43+
*
4444
* @param operations must not be {@literal null}.
4545
* @param context must not be {@literal null}.
4646
* @return the {@link List} of {@link DBObject}.

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
import com.mongodb.DBObject;
2424

2525
/**
26-
* Encapsulates the aggregation framework {@code $bucketAuto}-operation.
27-
* <p>
26+
* Encapsulates the aggregation framework {@code $bucketAuto}-operation. <br />
2827
* Bucket stage is typically used with {@link Aggregation} and {@code $facet}. Categorizes incoming documents into a
2928
* specific number of groups, called buckets, based on a specified expression. Bucket boundaries are automatically
30-
* determined in an attempt to evenly distribute the documents into the specified number of buckets.
31-
* <p>
32-
* We recommend to use the static factory method {@link Aggregation#bucketAuto(String, int)} instead of creating instances of
33-
* this class directly.
29+
* determined in an attempt to evenly distribute the documents into the specified number of buckets. <br />
30+
* We recommend to use the static factory method {@link Aggregation#bucketAuto(String, int)} instead of creating
31+
* instances of this class directly.
3432
*
35-
* @see http://docs.mongodb.org/manual/reference/aggregation/bucketAuto/
33+
* @see <a href=
34+
* "http://docs.mongodb.org/manual/reference/aggregation/bucketAuto/">http://docs.mongodb.org/manual/reference/aggregation/bucketAuto/</a>
3635
* @see BucketOperationSupport
3736
* @author Mark Paluch
37+
* @author Christoph Strobl
3838
* @since 1.10
3939
*/
4040
public class BucketAutoOperation extends BucketOperationSupport<BucketAutoOperation, BucketAutoOperationOutputBuilder>
@@ -100,13 +100,12 @@ public DBObject toDBObject(AggregationOperationContext context) {
100100
DBObject options = new BasicDBObject();
101101

102102
options.put("buckets", buckets);
103+
options.putAll(super.toDBObject(context));
103104

104105
if (granularity != null) {
105106
options.put("granularity", granularity);
106107
}
107108

108-
options.putAll(super.toDBObject(context));
109-
110109
return new BasicDBObject("$bucketAuto", options);
111110
}
112111

@@ -123,8 +122,10 @@ public BucketAutoOperation withBuckets(int buckets) {
123122
}
124123

125124
/**
126-
* Configures {@literal granularity} that specifies the preferred number series to use to ensure that the calculated
127-
* boundary edges end on preferred round numbers or their powers of 10 and return a new {@link BucketAutoOperation}.
125+
* Configures {@link Granularity granularity} that specifies the preferred number series to use to ensure that the
126+
* calculated boundary edges end on preferred round numbers or their powers of 10 and return a new
127+
* {@link BucketAutoOperation}. <br />
128+
* Use either predefined {@link Granularities} or provide a own one.
128129
*
129130
* @param granularity must not be {@literal null}.
130131
* @return
@@ -133,7 +134,7 @@ public BucketAutoOperation withGranularity(Granularity granularity) {
133134

134135
Assert.notNull(granularity, "Granularity must not be null!");
135136

136-
return new BucketAutoOperation(this, buckets, granularity.toMongoGranularity());
137+
return new BucketAutoOperation(this, buckets, granularity.getMongoRepresentation());
137138
}
138139

139140
/* (non-Javadoc)
@@ -196,7 +197,7 @@ protected BucketAutoOperationOutputBuilder apply(OperationOutput operationOutput
196197
/**
197198
* {@link ExpressionBucketOperationBuilderSupport} implementation for {@link BucketAutoOperation} using SpEL
198199
* expression based {@link Output}.
199-
*
200+
*
200201
* @author Mark Paluch
201202
*/
202203
public static class ExpressionBucketAutoOperationBuilder
@@ -227,19 +228,20 @@ protected BucketAutoOperationOutputBuilder apply(OperationOutput operationOutput
227228
/**
228229
* @author Mark Paluch
229230
*/
230-
public static interface Granularity {
231+
public interface Granularity {
231232

232233
/**
233-
* @return a String that represents a MongoDB granularity to be used with {@link BucketAutoOperation}.
234+
* @return a String that represents a MongoDB granularity to be used with {@link BucketAutoOperation}. Never
235+
* {@literal null}.
234236
*/
235-
String toMongoGranularity();
237+
String getMongoRepresentation();
236238
}
237239

238240
/**
239241
* Supported MongoDB granularities.
240242
*
241-
* @see https://en.wikipedia.org/wiki/Preferred_number
242-
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/bucketAuto/#granularity
243+
* @see <a
244+
* href="https://docs.mongodb.com/manual/reference/operator/aggregation/bucketAuto/#granularity>https://docs.mongodb.com/manual/reference/operator/aggregation/bucketAuto/#granularity</a>
243245
* @author Mark Paluch
244246
*/
245247
public enum Granularities implements Granularity {
@@ -252,7 +254,7 @@ public enum Granularities implements Granularity {
252254

253255
POWERSOF2;
254256

255-
final String granularity;
257+
private final String granularity;
256258

257259
Granularities() {
258260
this.granularity = name();
@@ -266,7 +268,7 @@ public enum Granularities implements Granularity {
266268
* @see org.springframework.data.mongodb.core.aggregation.GranularitytoMongoGranularity()
267269
*/
268270
@Override
269-
public String toMongoGranularity() {
271+
public String getMongoRepresentation() {
270272
return granularity;
271273
}
272274
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
import com.mongodb.DBObject;
2828

2929
/**
30-
* Encapsulates the aggregation framework {@code $bucket}-operation.
31-
* <p>
30+
* Encapsulates the aggregation framework {@code $bucket}-operation. <br />
31+
*
3232
* Bucket stage is typically used with {@link Aggregation} and {@code $facet}. Categorizes incoming documents into
33-
* groups, called buckets, based on a specified expression and bucket boundaries.
34-
* <p>
33+
* groups, called buckets, based on a specified expression and bucket boundaries. <br />
34+
*
3535
* We recommend to use the static factory method {@link Aggregation#bucket(String)} instead of creating instances of
3636
* this class directly.
3737
*
38-
* @see http://docs.mongodb.org/manual/reference/aggregation/bucket/
38+
* @see <a href="http://docs.mongodb.org/manual/reference/aggregation/bucket/">http://docs.mongodb.org/manual/reference/aggregation/bucket/</a>
3939
* @see BucketOperationSupport
4040
* @author Mark Paluch
4141
* @since 1.10
@@ -109,7 +109,7 @@ public DBObject toDBObject(AggregationOperationContext context) {
109109

110110
/**
111111
* Configures a default bucket {@literal literal} and return a new {@link BucketOperation}.
112-
*
112+
*
113113
* @param literal must not be {@literal null}.
114114
* @return
115115
*/
@@ -122,13 +122,14 @@ public BucketOperation withDefaultBucket(Object literal) {
122122
/**
123123
* Configures {@literal boundaries} and return a new {@link BucketOperation}. Existing {@literal boundaries} are
124124
* preserved and the new {@literal boundaries} are appended.
125-
*
125+
*
126126
* @param boundaries must not be {@literal null}.
127127
* @return
128128
*/
129129
public BucketOperation withBoundaries(Object... boundaries) {
130130

131131
Assert.notNull(boundaries, "Boundaries must not be null!");
132+
Assert.noNullElements(boundaries, "Boundaries must not contain null values!");
132133

133134
List<Object> newBoundaries = new ArrayList<Object>(this.boundaries.size() + boundaries.length);
134135
newBoundaries.addAll(this.boundaries);
@@ -197,7 +198,7 @@ protected BucketOperationOutputBuilder apply(OperationOutput operationOutput) {
197198
/**
198199
* {@link ExpressionBucketOperationBuilderSupport} implementation for {@link BucketOperation} using SpEL expression
199200
* based {@link Output}.
200-
*
201+
*
201202
* @author Mark Paluch
202203
*/
203204
public static class ExpressionBucketOperationBuilder

0 commit comments

Comments
 (0)