Skip to content

Commit 5cf8ec3

Browse files
DATAMONGO-1552 - Polishing.
Updated doc, removed whitespaces, minor method wording changes. Original Pull Request: spring-projects#426
1 parent 4505491 commit 5cf8ec3

File tree

9 files changed

+84
-99
lines changed

9 files changed

+84
-99
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ public static OutOperation out(String outCollectionName) {
422422
*
423423
* @param groupByField must not be {@literal null} or empty.
424424
* @return
425+
* @since 1.10
425426
*/
426427
public static BucketOperation bucket(String groupByField) {
427428
return new BucketOperation(field(groupByField));
@@ -432,6 +433,7 @@ public static BucketOperation bucket(String groupByField) {
432433
*
433434
* @param groupByExpression must not be {@literal null}.
434435
* @return
436+
* @since 1.10
435437
*/
436438
public static BucketOperation bucket(AggregationExpression groupByExpression) {
437439
return new BucketOperation(groupByExpression);
@@ -443,6 +445,7 @@ public static BucketOperation bucket(AggregationExpression groupByExpression) {
443445
* @param groupByField must not be {@literal null} or empty.
444446
* @param buckets number of buckets, must be a positive integer.
445447
* @return
448+
* @since 1.10
446449
*/
447450
public static BucketAutoOperation bucketAuto(String groupByField, int buckets) {
448451
return new BucketAutoOperation(field(groupByField), buckets);
@@ -454,6 +457,7 @@ public static BucketAutoOperation bucketAuto(String groupByField, int buckets) {
454457
* @param groupByExpression must not be {@literal null}.
455458
* @param buckets number of buckets, must be a positive integer.
456459
* @return
460+
* @since 1.10
457461
*/
458462
public static BucketAutoOperation bucketAuto(AggregationExpression groupByExpression, int buckets) {
459463
return new BucketAutoOperation(groupByExpression, buckets);
@@ -463,6 +467,7 @@ public static BucketAutoOperation bucketAuto(AggregationExpression groupByExpres
463467
* Creates a new {@link FacetOperation}.
464468
*
465469
* @return
470+
* @since 1.10
466471
*/
467472
public static FacetOperation facet() {
468473
return FacetOperation.EMPTY;
@@ -473,6 +478,7 @@ public static FacetOperation facet() {
473478
*
474479
* @param aggregationOperations the sub-pipeline, must not be {@literal null}.
475480
* @return
481+
* @since 1.10
476482
*/
477483
public static FacetOperationBuilder facet(AggregationOperation... aggregationOperations) {
478484
return facet().and(aggregationOperations);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AggregationOperationRenderer {
3939
/**
4040
* Render a {@link List} of {@link AggregationOperation} given {@link AggregationOperationContext} into their
4141
* {@link Document} representation.
42-
*
42+
*
4343
* @param operations must not be {@literal null}.
4444
* @param context must not be {@literal null}.
4545
* @return the {@link List} of {@link Document}.

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

+21-18
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
import org.bson.Document;
2323

2424
/**
25-
* Encapsulates the aggregation framework {@code $bucketAuto}-operation.
26-
* <p>
25+
* Encapsulates the aggregation framework {@code $bucketAuto}-operation. <br />
2726
* Bucket stage is typically used with {@link Aggregation} and {@code $facet}. Categorizes incoming documents into a
2827
* specific number of groups, called buckets, based on a specified expression. Bucket boundaries are automatically
29-
* determined in an attempt to evenly distribute the documents into the specified number of buckets.
30-
* <p>
31-
* We recommend to use the static factory method {@link Aggregation#bucketAuto(String, int)} instead of creating instances of
32-
* this class directly.
28+
* determined in an attempt to evenly distribute the documents into the specified number of buckets. <br />
29+
* We recommend to use the static factory method {@link Aggregation#bucketAuto(String, int)} instead of creating
30+
* instances of this class directly.
3331
*
34-
* @see http://docs.mongodb.org/manual/reference/aggregation/bucketAuto/
32+
* @see <a href=
33+
* "http://docs.mongodb.org/manual/reference/aggregation/bucketAuto/">http://docs.mongodb.org/manual/reference/aggregation/bucketAuto/</a>
3534
* @see BucketOperationSupport
3635
* @author Mark Paluch
36+
* @author Christoph Strobl
3737
* @since 1.10
3838
*/
3939
public class BucketAutoOperation extends BucketOperationSupport<BucketAutoOperation, BucketAutoOperationOutputBuilder>
@@ -122,8 +122,10 @@ public BucketAutoOperation withBuckets(int buckets) {
122122
}
123123

124124
/**
125-
* Configures {@literal granularity} that specifies the preferred number series to use to ensure that the calculated
126-
* 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.
127129
*
128130
* @param granularity must not be {@literal null}.
129131
* @return
@@ -132,7 +134,7 @@ public BucketAutoOperation withGranularity(Granularity granularity) {
132134

133135
Assert.notNull(granularity, "Granularity must not be null!");
134136

135-
return new BucketAutoOperation(this, buckets, granularity.toMongoGranularity());
137+
return new BucketAutoOperation(this, buckets, granularity.getMongoRepresentation());
136138
}
137139

138140
/* (non-Javadoc)
@@ -195,7 +197,7 @@ protected BucketAutoOperationOutputBuilder apply(OperationOutput operationOutput
195197
/**
196198
* {@link ExpressionBucketOperationBuilderSupport} implementation for {@link BucketAutoOperation} using SpEL
197199
* expression based {@link Output}.
198-
*
200+
*
199201
* @author Mark Paluch
200202
*/
201203
public static class ExpressionBucketAutoOperationBuilder
@@ -226,19 +228,20 @@ protected BucketAutoOperationOutputBuilder apply(OperationOutput operationOutput
226228
/**
227229
* @author Mark Paluch
228230
*/
229-
public static interface Granularity {
231+
public interface Granularity {
230232

231233
/**
232-
* @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}.
233236
*/
234-
String toMongoGranularity();
237+
String getMongoRepresentation();
235238
}
236239

237240
/**
238241
* Supported MongoDB granularities.
239242
*
240-
* @see https://en.wikipedia.org/wiki/Preferred_number
241-
* @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>
242245
* @author Mark Paluch
243246
*/
244247
public enum Granularities implements Granularity {
@@ -251,7 +254,7 @@ public enum Granularities implements Granularity {
251254

252255
POWERSOF2;
253256

254-
final String granularity;
257+
private final String granularity;
255258

256259
Granularities() {
257260
this.granularity = name();
@@ -265,7 +268,7 @@ public enum Granularities implements Granularity {
265268
* @see org.springframework.data.mongodb.core.aggregation.GranularitytoMongoGranularity()
266269
*/
267270
@Override
268-
public String toMongoGranularity() {
271+
public String getMongoRepresentation() {
269272
return granularity;
270273
}
271274
}

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
import org.bson.Document;
2727

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

109109
/**
110110
* Configures a default bucket {@literal literal} and return a new {@link BucketOperation}.
111-
*
111+
*
112112
* @param literal must not be {@literal null}.
113113
* @return
114114
*/
@@ -121,13 +121,14 @@ public BucketOperation withDefaultBucket(Object literal) {
121121
/**
122122
* Configures {@literal boundaries} and return a new {@link BucketOperation}. Existing {@literal boundaries} are
123123
* preserved and the new {@literal boundaries} are appended.
124-
*
124+
*
125125
* @param boundaries must not be {@literal null}.
126126
* @return
127127
*/
128128
public BucketOperation withBoundaries(Object... boundaries) {
129129

130130
Assert.notNull(boundaries, "Boundaries must not be null!");
131+
Assert.noNullElements(boundaries, "Boundaries must not contain null values!");
131132

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

0 commit comments

Comments
 (0)