2626import org .springframework .data .util .Optionals ;
2727import org .springframework .lang .Nullable ;
2828import org .springframework .util .Assert ;
29+ import org .springframework .util .ObjectUtils ;
2930
3031import com .mongodb .client .model .ValidationAction ;
3132import com .mongodb .client .model .ValidationLevel ;
@@ -49,8 +50,8 @@ public class CollectionOptions {
4950 private @ Nullable CollectionChangeStreamOptions changeStreamOptions ;
5051
5152 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 ) {
5455
5556 this .maxDocuments = maxDocuments ;
5657 this .size = size ;
@@ -104,7 +105,7 @@ public static CollectionOptions timeSeries(String timeField) {
104105 *
105106 * @return new instance of {@link CollectionOptions}.
106107 * @see #changeStream(CollectionChangeStreamOptions)
107- * @see CollectionChangeStreamOptions#preAndPostImages(boolean)
108+ * @see CollectionChangeStreamOptions#preAndPostImages(boolean)
108109 * @since 4.0
109110 */
110111 public static CollectionOptions emitChangedRevisions () {
@@ -119,7 +120,8 @@ public static CollectionOptions emitChangedRevisions() {
119120 * @since 2.0
120121 */
121122 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 );
123125 }
124126
125127 /**
@@ -130,7 +132,8 @@ public CollectionOptions capped() {
130132 * @since 2.0
131133 */
132134 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 );
134137 }
135138
136139 /**
@@ -141,7 +144,8 @@ public CollectionOptions maxDocuments(long maxDocuments) {
141144 * @since 2.0
142145 */
143146 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 );
145149 }
146150
147151 /**
@@ -152,7 +156,8 @@ public CollectionOptions size(long size) {
152156 * @since 2.0
153157 */
154158 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 );
156161 }
157162
158163 /**
@@ -272,7 +277,8 @@ public CollectionOptions schemaValidationAction(ValidationAction validationActio
272277 public CollectionOptions validation (ValidationOptions validationOptions ) {
273278
274279 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 );
276282 }
277283
278284 /**
@@ -285,7 +291,8 @@ public CollectionOptions validation(ValidationOptions validationOptions) {
285291 public CollectionOptions timeSeries (TimeSeriesOptions timeSeriesOptions ) {
286292
287293 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 );
289296 }
290297
291298 /**
@@ -298,7 +305,8 @@ public CollectionOptions timeSeries(TimeSeriesOptions timeSeriesOptions) {
298305 public CollectionOptions changeStream (CollectionChangeStreamOptions changeStreamOptions ) {
299306
300307 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 );
302310 }
303311
304312 /**
@@ -369,6 +377,60 @@ public Optional<CollectionChangeStreamOptions> getChangeStreamOptions() {
369377 return Optional .ofNullable (changeStreamOptions );
370378 }
371379
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+
372434 /**
373435 * Encapsulation of ValidationOptions options.
374436 *
@@ -463,6 +525,40 @@ public Optional<ValidationAction> getValidationAction() {
463525 boolean isEmpty () {
464526 return !Optionals .isAnyPresent (getValidator (), getValidationAction (), getValidationLevel ());
465527 }
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+ }
466562 }
467563
468564 /**
@@ -491,6 +587,30 @@ public static CollectionChangeStreamOptions preAndPostImages(boolean emitChanged
491587 public boolean getPreAndPostImages () {
492588 return preAndPostImages ;
493589 }
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+ }
494614 }
495615
496616 /**
@@ -576,5 +696,40 @@ public String getMetaField() {
576696 public GranularityDefinition getGranularity () {
577697 return granularity ;
578698 }
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+ }
579734 }
580735}
0 commit comments