|
| 1 | +/* |
| 2 | + * Copyright 2021 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.data.mongodb.core.aggregation; |
| 17 | + |
| 18 | +import org.bson.Document; |
| 19 | + |
| 20 | +/** |
| 21 | + * @author Christoph Strobl |
| 22 | + * @since 3.3 |
| 23 | + */ |
| 24 | +public class DocumentOperators { |
| 25 | + |
| 26 | + /** |
| 27 | + * Obtain the document position (including gaps) relative to others (rank). |
| 28 | + * |
| 29 | + * @return new instance of {@link Rank}. |
| 30 | + * @since 3.3 |
| 31 | + */ |
| 32 | + public static Rank rank() { |
| 33 | + return new Rank(); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Obtain the document position (without gaps) relative to others (rank). |
| 38 | + * |
| 39 | + * @return new instance of {@link DenseRank}. |
| 40 | + * @since 3.3 |
| 41 | + */ |
| 42 | + public static DenseRank denseRank() { |
| 43 | + return new DenseRank(); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * {@link Rank} resolves the current document position (the rank) relative to other documents. If multiple documents |
| 48 | + * occupy the same rank, {@literal $rank} places the document with the subsequent value at a rank with a gap. |
| 49 | + * |
| 50 | + * @author Christoph Strobl |
| 51 | + * @since 3.3 |
| 52 | + */ |
| 53 | + public static class Rank implements AggregationExpression { |
| 54 | + |
| 55 | + @Override |
| 56 | + public Document toDocument(AggregationOperationContext context) { |
| 57 | + return new Document("$rank", new Document()); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * {@link DenseRank} resolves the current document position (the rank) relative to other documents. If multiple |
| 63 | + * documents occupy the same rank, {@literal $denseRank} places the document with the subsequent value at the next rank without |
| 64 | + * any gaps. |
| 65 | + * |
| 66 | + * @author Christoph Strobl |
| 67 | + * @since 3.3 |
| 68 | + */ |
| 69 | + public static class DenseRank implements AggregationExpression { |
| 70 | + |
| 71 | + @Override |
| 72 | + public Document toDocument(AggregationOperationContext context) { |
| 73 | + return new Document("$denseRank", new Document()); |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments