26
26
import org .springframework .data .util .Optionals ;
27
27
import org .springframework .lang .Nullable ;
28
28
import org .springframework .util .Assert ;
29
+ import org .springframework .util .ObjectUtils ;
29
30
30
31
import com .mongodb .client .model .ValidationAction ;
31
32
import com .mongodb .client .model .ValidationLevel ;
@@ -49,8 +50,8 @@ public class CollectionOptions {
49
50
private @ Nullable CollectionChangeStreamOptions changeStreamOptions ;
50
51
51
52
private CollectionOptions (@ Nullable Long size , @ Nullable Long maxDocuments , @ Nullable Boolean capped ,
52
- @ Nullable Collation collation , ValidationOptions validationOptions ,
53
- @ Nullable TimeSeriesOptions timeSeriesOptions , @ Nullable CollectionChangeStreamOptions changeStreamOptions ) {
53
+ @ Nullable Collation collation , ValidationOptions validationOptions , @ Nullable TimeSeriesOptions timeSeriesOptions ,
54
+ @ Nullable CollectionChangeStreamOptions changeStreamOptions ) {
54
55
55
56
this .maxDocuments = maxDocuments ;
56
57
this .size = size ;
@@ -104,7 +105,7 @@ public static CollectionOptions timeSeries(String timeField) {
104
105
*
105
106
* @return new instance of {@link CollectionOptions}.
106
107
* @see #changeStream(CollectionChangeStreamOptions)
107
- * @see CollectionChangeStreamOptions#preAndPostImages(boolean)
108
+ * @see CollectionChangeStreamOptions#preAndPostImages(boolean)
108
109
* @since 4.0
109
110
*/
110
111
public static CollectionOptions emitChangedRevisions () {
@@ -119,7 +120,8 @@ public static CollectionOptions emitChangedRevisions() {
119
120
* @since 2.0
120
121
*/
121
122
public CollectionOptions capped () {
122
- return new CollectionOptions (size , maxDocuments , true , collation , validationOptions , timeSeriesOptions , changeStreamOptions );
123
+ return new CollectionOptions (size , maxDocuments , true , collation , validationOptions , timeSeriesOptions ,
124
+ changeStreamOptions );
123
125
}
124
126
125
127
/**
@@ -130,7 +132,8 @@ public CollectionOptions capped() {
130
132
* @since 2.0
131
133
*/
132
134
public CollectionOptions maxDocuments (long maxDocuments ) {
133
- return new CollectionOptions (size , maxDocuments , capped , collation , validationOptions , timeSeriesOptions , changeStreamOptions );
135
+ return new CollectionOptions (size , maxDocuments , capped , collation , validationOptions , timeSeriesOptions ,
136
+ changeStreamOptions );
134
137
}
135
138
136
139
/**
@@ -141,7 +144,8 @@ public CollectionOptions maxDocuments(long maxDocuments) {
141
144
* @since 2.0
142
145
*/
143
146
public CollectionOptions size (long size ) {
144
- return new CollectionOptions (size , maxDocuments , capped , collation , validationOptions , timeSeriesOptions , changeStreamOptions );
147
+ return new CollectionOptions (size , maxDocuments , capped , collation , validationOptions , timeSeriesOptions ,
148
+ changeStreamOptions );
145
149
}
146
150
147
151
/**
@@ -152,7 +156,8 @@ public CollectionOptions size(long size) {
152
156
* @since 2.0
153
157
*/
154
158
public CollectionOptions collation (@ Nullable Collation collation ) {
155
- return new CollectionOptions (size , maxDocuments , capped , collation , validationOptions , timeSeriesOptions , changeStreamOptions );
159
+ return new CollectionOptions (size , maxDocuments , capped , collation , validationOptions , timeSeriesOptions ,
160
+ changeStreamOptions );
156
161
}
157
162
158
163
/**
@@ -272,7 +277,8 @@ public CollectionOptions schemaValidationAction(ValidationAction validationActio
272
277
public CollectionOptions validation (ValidationOptions validationOptions ) {
273
278
274
279
Assert .notNull (validationOptions , "ValidationOptions must not be null" );
275
- return new CollectionOptions (size , maxDocuments , capped , collation , validationOptions , timeSeriesOptions , changeStreamOptions );
280
+ return new CollectionOptions (size , maxDocuments , capped , collation , validationOptions , timeSeriesOptions ,
281
+ changeStreamOptions );
276
282
}
277
283
278
284
/**
@@ -285,7 +291,8 @@ public CollectionOptions validation(ValidationOptions validationOptions) {
285
291
public CollectionOptions timeSeries (TimeSeriesOptions timeSeriesOptions ) {
286
292
287
293
Assert .notNull (timeSeriesOptions , "TimeSeriesOptions must not be null" );
288
- return new CollectionOptions (size , maxDocuments , capped , collation , validationOptions , timeSeriesOptions , changeStreamOptions );
294
+ return new CollectionOptions (size , maxDocuments , capped , collation , validationOptions , timeSeriesOptions ,
295
+ changeStreamOptions );
289
296
}
290
297
291
298
/**
@@ -298,7 +305,8 @@ public CollectionOptions timeSeries(TimeSeriesOptions timeSeriesOptions) {
298
305
public CollectionOptions changeStream (CollectionChangeStreamOptions changeStreamOptions ) {
299
306
300
307
Assert .notNull (changeStreamOptions , "ChangeStreamOptions must not be null" );
301
- return new CollectionOptions (size , maxDocuments , capped , collation , validationOptions , timeSeriesOptions , changeStreamOptions );
308
+ return new CollectionOptions (size , maxDocuments , capped , collation , validationOptions , timeSeriesOptions ,
309
+ changeStreamOptions );
302
310
}
303
311
304
312
/**
@@ -369,6 +377,60 @@ public Optional<CollectionChangeStreamOptions> getChangeStreamOptions() {
369
377
return Optional .ofNullable (changeStreamOptions );
370
378
}
371
379
380
+ @ Override
381
+ public String toString () {
382
+ return "CollectionOptions{" + "maxDocuments=" + maxDocuments + ", size=" + size + ", capped=" + capped
383
+ + ", collation=" + collation + ", validationOptions=" + validationOptions + ", timeSeriesOptions="
384
+ + timeSeriesOptions + ", changeStreamOptions=" + changeStreamOptions + ", disableValidation="
385
+ + disableValidation () + ", strictValidation=" + strictValidation () + ", moderateValidation="
386
+ + moderateValidation () + ", warnOnValidationError=" + warnOnValidationError () + ", failOnValidationError="
387
+ + failOnValidationError () + '}' ;
388
+ }
389
+
390
+ @ Override
391
+ public boolean equals (@ Nullable Object o ) {
392
+ if (this == o ) {
393
+ return true ;
394
+ }
395
+ if (o == null || getClass () != o .getClass ()) {
396
+ return false ;
397
+ }
398
+
399
+ CollectionOptions that = (CollectionOptions ) o ;
400
+
401
+ if (!ObjectUtils .nullSafeEquals (maxDocuments , that .maxDocuments )) {
402
+ return false ;
403
+ }
404
+ if (!ObjectUtils .nullSafeEquals (size , that .size )) {
405
+ return false ;
406
+ }
407
+ if (!ObjectUtils .nullSafeEquals (capped , that .capped )) {
408
+ return false ;
409
+ }
410
+ if (!ObjectUtils .nullSafeEquals (collation , that .collation )) {
411
+ return false ;
412
+ }
413
+ if (!ObjectUtils .nullSafeEquals (validationOptions , that .validationOptions )) {
414
+ return false ;
415
+ }
416
+ if (!ObjectUtils .nullSafeEquals (timeSeriesOptions , that .timeSeriesOptions )) {
417
+ return false ;
418
+ }
419
+ return ObjectUtils .nullSafeEquals (changeStreamOptions , that .changeStreamOptions );
420
+ }
421
+
422
+ @ Override
423
+ public int hashCode () {
424
+ int result = ObjectUtils .nullSafeHashCode (maxDocuments );
425
+ result = 31 * result + ObjectUtils .nullSafeHashCode (size );
426
+ result = 31 * result + ObjectUtils .nullSafeHashCode (capped );
427
+ result = 31 * result + ObjectUtils .nullSafeHashCode (collation );
428
+ result = 31 * result + ObjectUtils .nullSafeHashCode (validationOptions );
429
+ result = 31 * result + ObjectUtils .nullSafeHashCode (timeSeriesOptions );
430
+ result = 31 * result + ObjectUtils .nullSafeHashCode (changeStreamOptions );
431
+ return result ;
432
+ }
433
+
372
434
/**
373
435
* Encapsulation of ValidationOptions options.
374
436
*
@@ -463,6 +525,40 @@ public Optional<ValidationAction> getValidationAction() {
463
525
boolean isEmpty () {
464
526
return !Optionals .isAnyPresent (getValidator (), getValidationAction (), getValidationLevel ());
465
527
}
528
+
529
+ @ Override
530
+ public String toString () {
531
+
532
+ return "ValidationOptions{" + "validator=" + validator + ", validationLevel=" + validationLevel
533
+ + ", validationAction=" + validationAction + '}' ;
534
+ }
535
+
536
+ @ Override
537
+ public boolean equals (@ Nullable Object o ) {
538
+ if (this == o ) {
539
+ return true ;
540
+ }
541
+ if (o == null || getClass () != o .getClass ()) {
542
+ return false ;
543
+ }
544
+
545
+ ValidationOptions that = (ValidationOptions ) o ;
546
+
547
+ if (!ObjectUtils .nullSafeEquals (validator , that .validator )) {
548
+ return false ;
549
+ }
550
+ if (validationLevel != that .validationLevel )
551
+ return false ;
552
+ return validationAction == that .validationAction ;
553
+ }
554
+
555
+ @ Override
556
+ public int hashCode () {
557
+ int result = ObjectUtils .nullSafeHashCode (validator );
558
+ result = 31 * result + ObjectUtils .nullSafeHashCode (validationLevel );
559
+ result = 31 * result + ObjectUtils .nullSafeHashCode (validationAction );
560
+ return result ;
561
+ }
466
562
}
467
563
468
564
/**
@@ -491,6 +587,30 @@ public static CollectionChangeStreamOptions preAndPostImages(boolean emitChanged
491
587
public boolean getPreAndPostImages () {
492
588
return preAndPostImages ;
493
589
}
590
+
591
+ @ Override
592
+ public String toString () {
593
+ return "CollectionChangeStreamOptions{" + "preAndPostImages=" + preAndPostImages + '}' ;
594
+ }
595
+
596
+ @ Override
597
+ public boolean equals (@ Nullable Object o ) {
598
+ if (this == o ) {
599
+ return true ;
600
+ }
601
+ if (o == null || getClass () != o .getClass ()) {
602
+ return false ;
603
+ }
604
+
605
+ CollectionChangeStreamOptions that = (CollectionChangeStreamOptions ) o ;
606
+
607
+ return preAndPostImages == that .preAndPostImages ;
608
+ }
609
+
610
+ @ Override
611
+ public int hashCode () {
612
+ return (preAndPostImages ? 1 : 0 );
613
+ }
494
614
}
495
615
496
616
/**
@@ -576,5 +696,40 @@ public String getMetaField() {
576
696
public GranularityDefinition getGranularity () {
577
697
return granularity ;
578
698
}
699
+
700
+ @ Override
701
+ public String toString () {
702
+
703
+ return "TimeSeriesOptions{" + "timeField='" + timeField + '\'' + ", metaField='" + metaField + '\''
704
+ + ", granularity=" + granularity + '}' ;
705
+ }
706
+
707
+ @ Override
708
+ public boolean equals (@ Nullable Object o ) {
709
+ if (this == o ) {
710
+ return true ;
711
+ }
712
+ if (o == null || getClass () != o .getClass ()) {
713
+ return false ;
714
+ }
715
+
716
+ TimeSeriesOptions that = (TimeSeriesOptions ) o ;
717
+
718
+ if (!ObjectUtils .nullSafeEquals (timeField , that .timeField )) {
719
+ return false ;
720
+ }
721
+ if (!ObjectUtils .nullSafeEquals (metaField , that .metaField )) {
722
+ return false ;
723
+ }
724
+ return ObjectUtils .nullSafeEquals (granularity , that .granularity );
725
+ }
726
+
727
+ @ Override
728
+ public int hashCode () {
729
+ int result = ObjectUtils .nullSafeHashCode (timeField );
730
+ result = 31 * result + ObjectUtils .nullSafeHashCode (metaField );
731
+ result = 31 * result + ObjectUtils .nullSafeHashCode (granularity );
732
+ return result ;
733
+ }
579
734
}
580
735
}
0 commit comments