|
25 | 25 | import com.mongodb.DBObject;
|
26 | 26 | import org.bson.Document;
|
27 | 27 | import org.springframework.data.mongodb.core.aggregation.AggregationExpressions.Filter.AsBuilder;
|
28 |
| -import org.springframework.data.mongodb.core.aggregation.AggregationExpressions.Map.ArrayOfBuilder; |
29 | 28 | import org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField;
|
30 | 29 | import org.springframework.data.mongodb.core.aggregation.ExposedFields.FieldReference;
|
31 | 30 | import org.springframework.util.Assert;
|
@@ -1782,20 +1781,33 @@ private boolean usesFieldRef() {
|
1782 | 1781 | }
|
1783 | 1782 |
|
1784 | 1783 | /**
|
1785 |
| - * Gateway to {@literal Date} aggregation operations. |
| 1784 | + * Gateway to {@literal variable} aggregation operations. |
1786 | 1785 | *
|
1787 | 1786 | * @author Christoph Strobl
|
| 1787 | + * @author Mark Paluch |
1788 | 1788 | */
|
1789 | 1789 | class VariableOperators {
|
1790 | 1790 |
|
1791 | 1791 | /**
|
1792 | 1792 | * Starts building new {@link Map} that applies an {@link AggregationExpression} to each item of a referenced array
|
1793 | 1793 | * and returns an array with the applied results.
|
1794 | 1794 | *
|
| 1795 | + * @param fieldReference must not be {@literal null}. |
| 1796 | + * @return |
| 1797 | + */ |
| 1798 | + public static Map.AsBuilder mapItemsOf(String fieldReference) { |
| 1799 | + return Map.itemsOf(fieldReference); |
| 1800 | + } |
| 1801 | + |
| 1802 | + /** |
| 1803 | + * Starts building new {@link Map} that applies an {@link AggregationExpression} to each item of a referenced array |
| 1804 | + * and returns an array with the applied results. |
| 1805 | + * |
| 1806 | + * @param expression must not be {@literal null}. |
1795 | 1807 | * @return
|
1796 | 1808 | */
|
1797 |
| - public static ArrayOfBuilder map() { |
1798 |
| - return Map.map(); |
| 1809 | + public static Map.AsBuilder mapItemsOf(AggregationExpression expression) { |
| 1810 | + return Map.itemsOf(expression); |
1799 | 1811 | }
|
1800 | 1812 | }
|
1801 | 1813 |
|
@@ -5757,51 +5769,52 @@ private Map(Object sourceArray, String itemVariableName, AggregationExpression f
|
5757 | 5769 | * Starts building new {@link Map} that applies an {@link AggregationExpression} to each item of a referenced array
|
5758 | 5770 | * and returns an array with the applied results.
|
5759 | 5771 | *
|
| 5772 | + * @param fieldReference must not be {@literal null}. |
5760 | 5773 | * @return
|
5761 | 5774 | */
|
5762 |
| - static ArrayOfBuilder map() { |
| 5775 | + static AsBuilder itemsOf(final String fieldReference) { |
5763 | 5776 |
|
5764 |
| - return new ArrayOfBuilder() { |
| 5777 | + return new AsBuilder() { |
5765 | 5778 |
|
5766 | 5779 | @Override
|
5767 |
| - public AsBuilder itemsOf(final String fieldReference) { |
| 5780 | + public FunctionBuilder as(final String variableName) { |
5768 | 5781 |
|
5769 |
| - return new AsBuilder() { |
| 5782 | + return new FunctionBuilder() { |
5770 | 5783 |
|
5771 | 5784 | @Override
|
5772 |
| - public FunctionBuilder as(final String variableName) { |
5773 |
| - |
5774 |
| - return new FunctionBuilder() { |
5775 |
| - |
5776 |
| - @Override |
5777 |
| - public Map andApply(final AggregationExpression expression) { |
5778 |
| - return new Map(Fields.field(fieldReference), variableName, expression); |
5779 |
| - } |
5780 |
| - }; |
| 5785 | + public Map andApply(final AggregationExpression expression) { |
| 5786 | + return new Map(Fields.field(fieldReference), variableName, expression); |
5781 | 5787 | }
|
5782 | 5788 | };
|
5783 | 5789 | }
|
5784 | 5790 |
|
5785 |
| - @Override |
5786 |
| - public AsBuilder itemsOf(final AggregationExpression source) { |
| 5791 | + }; |
| 5792 | + }; |
5787 | 5793 |
|
5788 |
| - return new AsBuilder() { |
| 5794 | + /** |
| 5795 | + * Starts building new {@link Map} that applies an {@link AggregationExpression} to each item of a referenced array |
| 5796 | + * and returns an array with the applied results. |
| 5797 | + * |
| 5798 | + * @param source must not be {@literal null}. |
| 5799 | + * @return |
| 5800 | + */ |
| 5801 | + public static AsBuilder itemsOf(final AggregationExpression source) { |
5789 | 5802 |
|
5790 |
| - @Override |
5791 |
| - public FunctionBuilder as(final String variableName) { |
| 5803 | + return new AsBuilder() { |
| 5804 | + |
| 5805 | + @Override |
| 5806 | + public FunctionBuilder as(final String variableName) { |
5792 | 5807 |
|
5793 |
| - return new FunctionBuilder() { |
| 5808 | + return new FunctionBuilder() { |
5794 | 5809 |
|
5795 |
| - @Override |
5796 |
| - public Map andApply(final AggregationExpression expression) { |
5797 |
| - return new Map(source, variableName, expression); |
5798 |
| - } |
5799 |
| - }; |
| 5810 | + @Override |
| 5811 | + public Map andApply(final AggregationExpression expression) { |
| 5812 | + return new Map(source, variableName, expression); |
5800 | 5813 | }
|
5801 | 5814 | };
|
5802 | 5815 | }
|
5803 | 5816 | };
|
5804 |
| - }; |
| 5817 | + } |
5805 | 5818 |
|
5806 | 5819 | @Override
|
5807 | 5820 | public Document toDocument(final AggregationOperationContext context) {
|
@@ -5841,26 +5854,6 @@ private Document toMap(AggregationOperationContext context) {
|
5841 | 5854 | return new Document("$map", map);
|
5842 | 5855 | }
|
5843 | 5856 |
|
5844 |
| - interface ArrayOfBuilder { |
5845 |
| - |
5846 |
| - /** |
5847 |
| - * Set the field that resolves to an array on which to apply the {@link AggregationExpression}. |
5848 |
| - * |
5849 |
| - * @param fieldReference must not be {@literal null}. |
5850 |
| - * @return |
5851 |
| - */ |
5852 |
| - AsBuilder itemsOf(String fieldReference); |
5853 |
| - |
5854 |
| - /** |
5855 |
| - * Set the {@link AggregationExpression} that results in an array on which to apply the |
5856 |
| - * {@link AggregationExpression}. |
5857 |
| - * |
5858 |
| - * @param expression must not be {@literal null}. |
5859 |
| - * @return |
5860 |
| - */ |
5861 |
| - AsBuilder itemsOf(AggregationExpression expression); |
5862 |
| - } |
5863 |
| - |
5864 | 5857 | interface AsBuilder {
|
5865 | 5858 |
|
5866 | 5859 | /**
|
|
0 commit comments