Browse Source

Polishing.

See #4139
Original pull request: #4182.
pull/4212/head
Christoph Strobl 3 years ago committed by Mark Paluch
parent
commit
dd446472bc
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 16
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SelectionOperators.java
  2. 8
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SelectionOperatorUnitTests.java

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

@ -55,6 +55,14 @@ public class SelectionOperators {
return new Bottom(Collections.emptyMap()); return new Bottom(Collections.emptyMap());
} }
/**
* @param numberOfResults Limits the number of returned elements to the given value.
* @return new instance of {@link Bottom}.
*/
public static Bottom bottom(int numberOfResults) {
return bottom().limit(numberOfResults);
}
/** /**
* Limits the number of returned elements to the given value. * Limits the number of returned elements to the given value.
* *
@ -239,14 +247,14 @@ public class SelectionOperators {
* @return new instance of {@link First}. * @return new instance of {@link First}.
*/ */
public static First first() { public static First first() {
return new First(Collections.emptyMap()).limit(1); return new First(Collections.emptyMap());
} }
/** /**
* @return new instance of {@link First}. * @return new instance of {@link First}.
*/ */
public static First first(int numberOfResults) { public static First first(int numberOfResults) {
return new First(Collections.emptyMap()).limit(numberOfResults); return first().limit(numberOfResults);
} }
/** /**
@ -333,14 +341,14 @@ public class SelectionOperators {
* @return new instance of {@link Last}. * @return new instance of {@link Last}.
*/ */
public static Last last() { public static Last last() {
return new Last(Collections.emptyMap()).limit(1); return new Last(Collections.emptyMap());
} }
/** /**
* @return new instance of {@link Last}. * @return new instance of {@link Last}.
*/ */
public static Last last(int numberOfResults) { public static Last last(int numberOfResults) {
return new Last(Collections.emptyMap()).limit(numberOfResults); return last().limit(numberOfResults);
} }
/** /**

8
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SelectionOperatorUnitTests.java

@ -74,8 +74,8 @@ class SelectionOperatorUnitTests {
@Test // GH-4139 @Test // GH-4139
void bottomNRenderedCorrectly() { void bottomNRenderedCorrectly() {
Document document = SelectionOperators.Bottom.bottom().output(Fields.fields("playerId", "score")) Document document = SelectionOperators.Bottom.bottom(3).output(Fields.fields("playerId", "score"))
.sortBy(Sort.by(Direction.DESC, "score")).limit(3).toDocument(Aggregation.DEFAULT_CONTEXT); .sortBy(Sort.by(Direction.DESC, "score")).toDocument(Aggregation.DEFAULT_CONTEXT);
assertThat(document).isEqualTo(Document.parse(""" assertThat(document).isEqualTo(Document.parse("""
{ {
@ -114,8 +114,8 @@ class SelectionOperatorUnitTests {
@Test // GH-4139 @Test // GH-4139
void topNRenderedCorrectly() { void topNRenderedCorrectly() {
Document document = SelectionOperators.Top.top().output(Fields.fields("playerId", "score")) Document document = SelectionOperators.Top.top(3).output(Fields.fields("playerId", "score"))
.sortBy(Sort.by(Direction.DESC, "score")).limit(3).toDocument(Aggregation.DEFAULT_CONTEXT); .sortBy(Sort.by(Direction.DESC, "score")).toDocument(Aggregation.DEFAULT_CONTEXT);
assertThat(document).isEqualTo(Document.parse(""" assertThat(document).isEqualTo(Document.parse("""
{ {

Loading…
Cancel
Save