33import org .bson .types .Code ;
44import org .mongodb .Document ;
55
6+ /**
7+ * A class that groups arguments for a map/reduce operation.
8+ */
69public class MapReduce {
710 private final Code mapFunction ;
811 private final Code reduceFunction ;
@@ -16,13 +19,26 @@ public class MapReduce {
1619 private boolean jsMode ;
1720 private boolean verbose ;
1821
22+ /**
23+ * Constructs a new instance of the {@code MapReduce} with output to a another collection.
24+ *
25+ * @param mapFunction a JavaScript function that associates or “maps” a value with a key and emits the key and value pair.
26+ * @param reduceFunction a JavaScript function that “reduces” to a single object all the values associated with a particular key.
27+ * @param output specifies the location of the result of the map-reduce operation.
28+ */
1929 public MapReduce (final Code mapFunction , final Code reduceFunction , final MapReduceOutput output ) {
2030 this .mapFunction = mapFunction ;
2131 this .reduceFunction = reduceFunction ;
2232 this .output = output ;
2333 this .inline = false ;
2434 }
2535
36+ /**
37+ * Constructs a new instance of the {@code MapReduce} with result to be inlined into response.
38+ *
39+ * @param mapFunction a JavaScript function that associates or “maps” a value with a key and emits the key and value pair.
40+ * @param reduceFunction a JavaScript function that “reduces” to a single object all the values associated with a particular key.
41+ */
2642 public MapReduce (final Code mapFunction , final Code reduceFunction ) {
2743 this .mapFunction = mapFunction ;
2844 this .reduceFunction = reduceFunction ;
@@ -31,38 +47,84 @@ public MapReduce(final Code mapFunction, final Code reduceFunction) {
3147 this .output = null ;
3248 }
3349
50+ /**
51+ * Add a 'finalize' argument to the command.
52+ *
53+ * @param finalize a JavaScript function that follows the reduce method and modifies the output.
54+ * @return the same {@code MapReduce} instance as used for the method invocation for chaining
55+ */
3456 public MapReduce finalize (final Code finalize ) {
3557 this .finalizeFunction = finalize ;
3658 return this ;
3759 }
3860
39- //CHECKSTYLE:OFF TODO: http://checkstyle.sourceforge.net/config_coding.html#HiddenField needs to be supressed?
61+ //CHECKSTYLE:OFF
62+
63+ /**
64+ * Add a 'query' argument to the command.
65+ *
66+ * @param filter the selection criteria using query operators for determining the documents input to the map function.
67+ * @return the same {@code MapReduce} instance as used for the method invocation for chaining
68+ */
4069 public MapReduce filter (final Document filter ) {
4170 this .filter = filter ;
4271 return this ;
4372 }
4473
74+ /**
75+ * Add a 'sort' argument to the command.
76+ *
77+ * @param sortCriteria sorts the input documents. This option is useful for optimization.
78+ * @return the same {@code MapReduce} instance as used for the method invocation for chaining
79+ */
4580 public MapReduce sort (final Document sortCriteria ) {
4681 this .sortCriteria = sortCriteria ;
4782 return this ;
4883 }
4984
85+ /**
86+ * Add a 'scope' argument to the command.
87+ *
88+ * @param scope specifies global variables that are accessible in the map , reduce and the finalize functions
89+ * @return the same {@code MapReduce} instance as used for the method invocation for chaining
90+ */
5091 public MapReduce scope (final Document scope ) {
5192 this .scope = scope ;
5293 return this ;
5394 }
5495
96+ /**
97+ * Add a 'limit' argument to the command.
98+ *
99+ * @param limit specifies a maximum number of documents to return from the collection.
100+ * @return the same {@code MapReduce} instance as used for the method invocation for chaining
101+ */
55102 public MapReduce limit (final int limit ) {
56103 this .limit = limit ;
57104 return this ;
58105 }
59106 //CHECKSTYLE:ON
60107
108+ /**
109+ * Add a 'jsMode' flag to the command.
110+ * <p/>
111+ * This flag specifies whether to convert intermediate data into BSON format
112+ * between the execution of the map and reduce functions
113+ *
114+ * @return the same {@code MapReduce} instance as used for the method invocation for chaining
115+ */
61116 public MapReduce jsMode () {
62117 this .jsMode = true ;
63118 return this ;
64119 }
65120
121+ /**
122+ * Add a 'verbose' flag to the command.
123+ * <p/>
124+ * This flag specifies whether to include the timing information in the result information.
125+ *
126+ * @return the same {@code MapReduce} instance as used for the method invocation for chaining
127+ */
66128 public MapReduce verbose () {
67129 this .verbose = true ;
68130 return this ;
0 commit comments