Skip to content

Commit dd44647

Browse files
christophstroblmp911de
authored andcommitted
Polishing.
See #4139 Original pull request: #4182.
1 parent 72d82d3 commit dd44647

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Diff for: spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SelectionOperators.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ public static Bottom bottom() {
5555
return new Bottom(Collections.emptyMap());
5656
}
5757

58+
/**
59+
* @param numberOfResults Limits the number of returned elements to the given value.
60+
* @return new instance of {@link Bottom}.
61+
*/
62+
public static Bottom bottom(int numberOfResults) {
63+
return bottom().limit(numberOfResults);
64+
}
65+
5866
/**
5967
* Limits the number of returned elements to the given value.
6068
*
@@ -239,14 +247,14 @@ protected First(Object value) {
239247
* @return new instance of {@link First}.
240248
*/
241249
public static First first() {
242-
return new First(Collections.emptyMap()).limit(1);
250+
return new First(Collections.emptyMap());
243251
}
244252

245253
/**
246254
* @return new instance of {@link First}.
247255
*/
248256
public static First first(int numberOfResults) {
249-
return new First(Collections.emptyMap()).limit(numberOfResults);
257+
return first().limit(numberOfResults);
250258
}
251259

252260
/**
@@ -333,14 +341,14 @@ protected Last(Object value) {
333341
* @return new instance of {@link Last}.
334342
*/
335343
public static Last last() {
336-
return new Last(Collections.emptyMap()).limit(1);
344+
return new Last(Collections.emptyMap());
337345
}
338346

339347
/**
340348
* @return new instance of {@link Last}.
341349
*/
342350
public static Last last(int numberOfResults) {
343-
return new Last(Collections.emptyMap()).limit(numberOfResults);
351+
return last().limit(numberOfResults);
344352
}
345353

346354
/**

Diff for: spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SelectionOperatorUnitTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ void bottomMapsFieldNamesCorrectly() {
7474
@Test // GH-4139
7575
void bottomNRenderedCorrectly() {
7676

77-
Document document = SelectionOperators.Bottom.bottom().output(Fields.fields("playerId", "score"))
78-
.sortBy(Sort.by(Direction.DESC, "score")).limit(3).toDocument(Aggregation.DEFAULT_CONTEXT);
77+
Document document = SelectionOperators.Bottom.bottom(3).output(Fields.fields("playerId", "score"))
78+
.sortBy(Sort.by(Direction.DESC, "score")).toDocument(Aggregation.DEFAULT_CONTEXT);
7979

8080
assertThat(document).isEqualTo(Document.parse("""
8181
{
@@ -114,8 +114,8 @@ void topMapsFieldNamesCorrectly() {
114114
@Test // GH-4139
115115
void topNRenderedCorrectly() {
116116

117-
Document document = SelectionOperators.Top.top().output(Fields.fields("playerId", "score"))
118-
.sortBy(Sort.by(Direction.DESC, "score")).limit(3).toDocument(Aggregation.DEFAULT_CONTEXT);
117+
Document document = SelectionOperators.Top.top(3).output(Fields.fields("playerId", "score"))
118+
.sortBy(Sort.by(Direction.DESC, "score")).toDocument(Aggregation.DEFAULT_CONTEXT);
119119

120120
assertThat(document).isEqualTo(Document.parse("""
121121
{

0 commit comments

Comments
 (0)