@@ -686,28 +686,70 @@ public RegexMatch regexMatch(String regex, String options) {
686
686
private RegexMatch createRegexMatch () {
687
687
return usesFieldRef () ? RegexMatch .valueOf (fieldReference ) : RegexMatch .valueOf (expression );
688
688
}
689
-
690
- public ReplaceOne replaceOne (String find ,String replacement ) {
691
- return createReplaceOne ().find (find ).replacement (replacement );
689
+
690
+ /**
691
+ * Creates new {@link AggregationExpression} that takes the associated string representation and replaces the first
692
+ * occurrence of the search string with the given replacement.
693
+ *
694
+ * @param search
695
+ * @param replacement
696
+ * @return new instance of {@link ReplaceOne}.
697
+ * @since 3.4
698
+ */
699
+ public ReplaceOne replaceOne (String search , String replacement ) {
700
+ return createReplaceOne ().find (search ).replacement (replacement );
692
701
}
693
-
702
+
703
+ /**
704
+ * Creates new {@link AggregationExpression} that takes the associated string representation and replaces the first
705
+ * occurrence of the search string computed by the given {@link AggregationExpression} with the given replacement.
706
+ *
707
+ * @param search
708
+ * @param replacement
709
+ * @return new instance of {@link ReplaceOne}.
710
+ * @since 3.4
711
+ */
712
+ public ReplaceOne replaceOne (AggregationExpression search , String replacement ) {
713
+ return createReplaceOne ().findValueOf (search ).replacement (replacement );
714
+ }
715
+
694
716
private ReplaceOne createReplaceOne () {
695
717
return usesFieldRef () ? ReplaceOne .valueOf (fieldReference ) : ReplaceOne .valueOf (expression );
696
718
}
697
-
698
- public ReplaceAll replaceAll (String find ,String replacement ) {
699
- return createReplaceAll ().find (find ).replacement (replacement );
719
+
720
+ /**
721
+ * Creates new {@link AggregationExpression} that takes the associated string representation and replaces all
722
+ * occurrences of the search string with the given replacement.
723
+ *
724
+ * @param search
725
+ * @param replacement
726
+ * @return new instance of {@link ReplaceOne}.
727
+ * @since 3.4
728
+ */
729
+ public ReplaceAll replaceAll (String search , String replacement ) {
730
+ return createReplaceAll ().find (search ).replacement (replacement );
731
+ }
732
+
733
+ /**
734
+ * Creates new {@link AggregationExpression} that takes the associated string representation and replaces all
735
+ * occurrences of the search string computed by the given {@link AggregationExpression} with the given replacement.
736
+ *
737
+ * @param search
738
+ * @param replacement
739
+ * @return new instance of {@link ReplaceOne}.
740
+ * @since 3.4
741
+ */
742
+ public ReplaceAll replaceAll (AggregationExpression search , String replacement ) {
743
+ return createReplaceAll ().findValueOf (search ).replacement (replacement );
700
744
}
701
-
745
+
702
746
private ReplaceAll createReplaceAll () {
703
747
return usesFieldRef () ? ReplaceAll .valueOf (fieldReference ) : ReplaceAll .valueOf (expression );
704
748
}
705
749
706
750
private boolean usesFieldRef () {
707
751
return fieldReference != null ;
708
752
}
709
-
710
-
711
753
}
712
754
713
755
/**
@@ -2096,18 +2138,35 @@ protected String getMongoMethod() {
2096
2138
return "$regexMatch" ;
2097
2139
}
2098
2140
}
2099
-
2141
+
2100
2142
/**
2101
2143
* {@link AggregationExpression} for {@code $replaceOne} which replaces the first instance of a search string in an
2102
2144
* input string with a replacement string. <br />
2103
2145
* <strong>NOTE:</strong> Requires MongoDB 4.4 or later.
2146
+ *
2147
+ * @author Divya Srivastava
2148
+ * @author Christoph Strobl
2149
+ * @since 3.4
2104
2150
*/
2105
2151
public static class ReplaceOne extends AbstractAggregationExpression {
2106
2152
2107
2153
protected ReplaceOne (Object value ) {
2108
2154
super (value );
2109
2155
}
2110
2156
2157
+ /**
2158
+ * Creates new {@link ReplaceOne} using the given as {@literal input}.
2159
+ *
2160
+ * @param value must not be {@literal null}.
2161
+ * @return new instance of {@link ReplaceOne}.
2162
+ */
2163
+ public static ReplaceOne value (String value ) {
2164
+
2165
+ Assert .notNull (value , "Value must not be null!" );
2166
+
2167
+ return new ReplaceOne (Collections .singletonMap ("input" , value ));
2168
+ }
2169
+
2111
2170
/**
2112
2171
* Creates new {@link ReplaceOne} using the value of the provided {@link Field fieldReference} as {@literal input}
2113
2172
* value.
@@ -2180,25 +2239,23 @@ public ReplaceOne replacementOf(AggregationExpression expression) {
2180
2239
/**
2181
2240
* The string to search for within the given input field.
2182
2241
*
2183
- * @param find must not be {@literal null}.
2242
+ * @param value must not be {@literal null}.
2184
2243
* @return new instance of {@link ReplaceOne}.
2185
2244
*/
2186
- public ReplaceOne find (String searchStr ) {
2245
+ public ReplaceOne find (String value ) {
2187
2246
2188
- Assert .notNull (searchStr , "Search string must not be null!" );
2247
+ Assert .notNull (value , "Search string must not be null!" );
2189
2248
2190
- Map <String , Object > search = append ("find" , searchStr );
2191
-
2192
- return new ReplaceOne (search );
2249
+ return new ReplaceOne (append ("find" , value ));
2193
2250
}
2194
2251
2195
2252
/**
2196
2253
* Specify the reference to the {@link Field field} holding the string to search for within the given input field.
2197
2254
*
2198
- * @param find must not be {@literal null}.
2255
+ * @param fieldReference must not be {@literal null}.
2199
2256
* @return new instance of {@link ReplaceOne}.
2200
2257
*/
2201
- public ReplaceOne findOf (String fieldReference ) {
2258
+ public ReplaceOne findValueOf (String fieldReference ) {
2202
2259
2203
2260
Assert .notNull (fieldReference , "fieldReference must not be null!" );
2204
2261
@@ -2212,7 +2269,7 @@ public ReplaceOne findOf(String fieldReference) {
2212
2269
* @param expression must not be {@literal null}.
2213
2270
* @return new instance of {@link ReplaceOne}.
2214
2271
*/
2215
- public ReplaceOne findOf (AggregationExpression expression ) {
2272
+ public ReplaceOne findValueOf (AggregationExpression expression ) {
2216
2273
2217
2274
Assert .notNull (expression , "Expression must not be null!" );
2218
2275
@@ -2224,18 +2281,35 @@ protected String getMongoMethod() {
2224
2281
return "$replaceOne" ;
2225
2282
}
2226
2283
}
2227
-
2284
+
2228
2285
/**
2229
2286
* {@link AggregationExpression} for {@code $replaceAll} which replaces all instances of a search string in an input
2230
2287
* string with a replacement string. <br />
2231
2288
* <strong>NOTE:</strong> Requires MongoDB 4.4 or later.
2289
+ *
2290
+ * @author Divya Srivastava
2291
+ * @author Christoph Strobl
2292
+ * @since 3.4
2232
2293
*/
2233
2294
public static class ReplaceAll extends AbstractAggregationExpression {
2234
2295
2235
2296
protected ReplaceAll (Object value ) {
2236
2297
super (value );
2237
2298
}
2238
2299
2300
+ /**
2301
+ * Creates new {@link ReplaceAll} using the given as {@literal input}.
2302
+ *
2303
+ * @param value must not be {@literal null}.
2304
+ * @return new instance of {@link ReplaceOne}.
2305
+ */
2306
+ public static ReplaceAll value (String value ) {
2307
+
2308
+ Assert .notNull (value , "Value must not be null!" );
2309
+
2310
+ return new ReplaceAll (Collections .singletonMap ("input" , value ));
2311
+ }
2312
+
2239
2313
/**
2240
2314
* Creates new {@link ReplaceAll} using the value of the provided {@link Field fieldReference} as {@literal input}
2241
2315
* value.
@@ -2284,7 +2358,7 @@ public ReplaceAll replacement(String replacement) {
2284
2358
* @param fieldReference must not be {@literal null}.
2285
2359
* @return new instance of {@link ReplaceAll}.
2286
2360
*/
2287
- public ReplaceAll replacementOf (String fieldReference ) {
2361
+ public ReplaceAll replacementValueOf (String fieldReference ) {
2288
2362
2289
2363
Assert .notNull (fieldReference , "FieldReference must not be null!" );
2290
2364
@@ -2298,7 +2372,7 @@ public ReplaceAll replacementOf(String fieldReference) {
2298
2372
* @param expression must not be {@literal null}.
2299
2373
* @return new instance of {@link ReplaceAll}.
2300
2374
*/
2301
- public ReplaceAll replacementOf (AggregationExpression expression ) {
2375
+ public ReplaceAll replacementValueOf (AggregationExpression expression ) {
2302
2376
2303
2377
Assert .notNull (expression , "Expression must not be null!" );
2304
2378
@@ -2308,25 +2382,23 @@ public ReplaceAll replacementOf(AggregationExpression expression) {
2308
2382
/**
2309
2383
* The string to search for within the given input field.
2310
2384
*
2311
- * @param find must not be {@literal null}.
2385
+ * @param value must not be {@literal null}.
2312
2386
* @return new instance of {@link ReplaceAll}.
2313
2387
*/
2314
- public ReplaceAll find (String searchStr ) {
2315
-
2316
- Assert .notNull (searchStr , "Search string must not be null!" );
2388
+ public ReplaceAll find (String value ) {
2317
2389
2318
- Map < String , Object > search = append ( "find" , searchStr );
2390
+ Assert . notNull ( value , "Search string must not be null!" );
2319
2391
2320
- return new ReplaceAll (search );
2392
+ return new ReplaceAll (append ( "find" , value ) );
2321
2393
}
2322
2394
2323
2395
/**
2324
2396
* Specify the reference to the {@link Field field} holding the string to search for within the given input field.
2325
2397
*
2326
- * @param find must not be {@literal null}.
2398
+ * @param fieldReference must not be {@literal null}.
2327
2399
* @return new instance of {@link ReplaceAll}.
2328
2400
*/
2329
- public ReplaceAll findOf (String fieldReference ) {
2401
+ public ReplaceAll findValueOf (String fieldReference ) {
2330
2402
2331
2403
Assert .notNull (fieldReference , "fieldReference must not be null!" );
2332
2404
@@ -2339,7 +2411,7 @@ public ReplaceAll findOf(String fieldReference) {
2339
2411
* @param expression must not be {@literal null}.
2340
2412
* @return new instance of {@link ReplaceAll}.
2341
2413
*/
2342
- public ReplaceAll findOf (AggregationExpression expression ) {
2414
+ public ReplaceAll findValueOf (AggregationExpression expression ) {
2343
2415
2344
2416
Assert .notNull (expression , "Expression must not be null!" );
2345
2417
0 commit comments