28
28
*/
29
29
public class CollectionOptions {
30
30
31
- private Integer maxDocuments ;
32
- private Integer size ;
31
+ private Long maxDocuments ;
32
+ private Long size ;
33
33
private Boolean capped ;
34
- private Optional < Collation > collation ;
34
+ private Collation collation ;
35
35
36
36
/**
37
37
* Constructs a new <code>CollectionOptions</code> instance.
@@ -40,23 +40,21 @@ public class CollectionOptions {
40
40
* @param maxDocuments the maximum number of documents in the collection.
41
41
* @param capped true to created a "capped" collection (fixed size with auto-FIFO behavior based on insertion order),
42
42
* false otherwise.
43
+ * @deprecated since 2.0 please use {@link CollectionOptions#empty()} as entry point.
43
44
*/
44
- public CollectionOptions (Integer size , Integer maxDocuments , Boolean capped ) {
45
- this (size , maxDocuments , capped , Optional .empty ());
45
+ @ Deprecated
46
+ public CollectionOptions (Long size , Long maxDocuments , Boolean capped ) {
47
+ this (size , maxDocuments , capped , null );
46
48
}
47
49
48
- private CollectionOptions (Integer size , Integer maxDocuments , Boolean capped , Optional < Collation > collation ) {
50
+ private CollectionOptions (Long size , Long maxDocuments , Boolean capped , Collation collation ) {
49
51
50
52
this .maxDocuments = maxDocuments ;
51
53
this .size = size ;
52
54
this .capped = capped ;
53
55
this .collation = collation ;
54
56
}
55
57
56
- private CollectionOptions () {
57
- this .collation = Optional .empty ();
58
- }
59
-
60
58
/**
61
59
* Create new {@link CollectionOptions} by just providing the {@link Collation} to use.
62
60
*
@@ -68,9 +66,7 @@ public static CollectionOptions just(Collation collation) {
68
66
69
67
Assert .notNull (collation , "Collation must not be null!" );
70
68
71
- CollectionOptions options = new CollectionOptions ();
72
- options .setCollation (collation );
73
- return options ;
69
+ return new CollectionOptions (null , null , null , collation );
74
70
}
75
71
76
72
/**
@@ -80,17 +76,17 @@ public static CollectionOptions just(Collation collation) {
80
76
* @since 2.0
81
77
*/
82
78
public static CollectionOptions empty () {
83
- return new CollectionOptions ();
79
+ return new CollectionOptions (null , null , null , null );
84
80
}
85
81
86
82
/**
87
- * Create new {@link CollectionOptions} with already given settings and capped set to {@literal true}.
83
+ * Create new {@link CollectionOptions} with already given settings and capped set to {@literal true}. <br />
84
+ * <strong>NOTE</strong> Using capped collections requires defining {@link #size(int)}.
88
85
*
89
- * @param size the collection size in bytes, this data space is preallocated.
90
86
* @return new {@link CollectionOptions}.
91
87
* @since 2.0
92
88
*/
93
- public CollectionOptions capped (int size ) {
89
+ public CollectionOptions capped () {
94
90
return new CollectionOptions (size , maxDocuments , true , collation );
95
91
}
96
92
@@ -101,7 +97,7 @@ public CollectionOptions capped(int size) {
101
97
* @return new {@link CollectionOptions}.
102
98
* @since 2.0
103
99
*/
104
- public CollectionOptions maxDocuments (Integer maxDocuments ) {
100
+ public CollectionOptions maxDocuments (long maxDocuments ) {
105
101
return new CollectionOptions (size , maxDocuments , capped , collation );
106
102
}
107
103
@@ -112,7 +108,7 @@ public CollectionOptions maxDocuments(Integer maxDocuments) {
112
108
* @return new {@link CollectionOptions}.
113
109
* @since 2.0
114
110
*/
115
- public CollectionOptions size (int size ) {
111
+ public CollectionOptions size (long size ) {
116
112
return new CollectionOptions (size , maxDocuments , capped , collation );
117
113
}
118
114
@@ -124,50 +120,44 @@ public CollectionOptions size(int size) {
124
120
* @since 2.0
125
121
*/
126
122
public CollectionOptions collation (Collation collation ) {
127
- return new CollectionOptions (size , maxDocuments , capped , Optional .ofNullable (collation ));
128
- }
129
-
130
- public Integer getMaxDocuments () {
131
- return maxDocuments ;
132
- }
133
-
134
- public void setMaxDocuments (Integer maxDocuments ) {
135
- this .maxDocuments = maxDocuments ;
136
- }
137
-
138
- public Integer getSize () {
139
- return size ;
140
- }
141
-
142
- public void setSize (Integer size ) {
143
- this .size = size ;
123
+ return new CollectionOptions (size , maxDocuments , capped , collation );
144
124
}
145
125
146
- public Boolean getCapped () {
147
- return capped ;
126
+ /**
127
+ * Get the max number of documents the collection should be limited to.
128
+ *
129
+ * @return {@link Optional#empty()} if not set.
130
+ */
131
+ public Optional <Long > getMaxDocuments () {
132
+ return Optional .ofNullable (maxDocuments );
148
133
}
149
134
150
- public void setCapped (Boolean capped ) {
151
- this .capped = capped ;
135
+ /**
136
+ * Get the {@literal size} in bytes the collection should be limited to.
137
+ *
138
+ * @return {@link Optional#empty()} if not set.
139
+ */
140
+ public Optional <Long > getSize () {
141
+ return Optional .ofNullable (size );
152
142
}
153
143
154
144
/**
155
- * Set {@link Collation} options .
145
+ * Get if the collection should be capped .
156
146
*
157
- * @param collation
147
+ * @return {@link Optional#empty()} if not set.
158
148
* @since 2.0
159
149
*/
160
- public void setCollation ( Collation collation ) {
161
- this . collation = Optional .ofNullable (collation );
150
+ public Optional < Boolean > getCapped ( ) {
151
+ return Optional .ofNullable (capped );
162
152
}
163
153
164
154
/**
165
155
* Get the {@link Collation} settings.
166
156
*
167
- * @return
157
+ * @return {@link Optional#empty()} if not set.
168
158
* @since 2.0
169
159
*/
170
160
public Optional <Collation > getCollation () {
171
- return collation ;
161
+ return Optional . ofNullable ( collation ) ;
172
162
}
173
163
}
0 commit comments