You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add testLang1641()
* Rename some test methods
* Add long support to BitField
* Remove unnecessary blank line in BitFieldTest
* Fix missing newline at end of file
Add missing newline at the end of BitFieldLongTest.java
* Fix return value
* Use final
* Add more tests
* @param holder the int data containing the bits we're interested in.
93
104
* @return the value of holder with the specified bits cleared (set to {@code 0}).
94
105
*/
95
106
publicintclear(finalintholder) {
107
+
return (int) (holder & ~mask);
108
+
}
109
+
110
+
/**
111
+
* Clears the bits.
112
+
*
113
+
* @param holder the long data containing the bits we're interested in.
114
+
* @return the value of holder with the specified bits cleared (set to {@code 0}).
115
+
* @since 3.21.0
116
+
*/
117
+
publiclongclear(finallongholder) {
96
118
returnholder & ~mask;
97
119
}
98
120
@@ -123,6 +145,17 @@ public short clearShort(final short holder) {
123
145
* @return the selected bits.
124
146
*/
125
147
publicintgetRawValue(finalintholder) {
148
+
return (int) (holder & mask);
149
+
}
150
+
151
+
/**
152
+
* Gets the value for the specified BitField, unshifted.
153
+
*
154
+
* @param holder the long data containing the bits we're interested in.
155
+
* @return the selected bits.
156
+
* @since 3.21.0
157
+
*/
158
+
publiclonggetRawValue(finallongholder) {
126
159
returnholder & mask;
127
160
}
128
161
@@ -166,6 +199,22 @@ public int getValue(final int holder) {
166
199
returngetRawValue(holder) >> shiftCount;
167
200
}
168
201
202
+
/**
203
+
* Gets the value for the specified BitField, appropriately shifted right.
204
+
* <p>
205
+
* Many users of a BitField will want to treat the specified bits as an long value, and will not want to be aware that the value is stored as a BitField (and
206
+
* so shifted left so many bits).
207
+
* </p>
208
+
*
209
+
* @param holder the long data containing the bits we're interested in.
210
+
* @return the selected bits, shifted right appropriately.
211
+
* @see #setValue(long,long)
212
+
* @since 3.21.0
213
+
*/
214
+
publiclonggetValue(finallongholder) {
215
+
returngetRawValue(holder) >> shiftCount;
216
+
}
217
+
169
218
/**
170
219
* Tests whether all of the bits are set or not.
171
220
* <p>
@@ -179,11 +228,25 @@ public boolean isAllSet(final int holder) {
179
228
return (holder & mask) == mask;
180
229
}
181
230
231
+
/**
232
+
* Tests whether all of the bits are set or not.
233
+
* <p>
234
+
* This is a stricter test than {@link #isSet(long)}, in that all of the bits in a multi-bit set must be set for this method to return {@code true}.
235
+
* </p>
236
+
*
237
+
* @param holder the long data containing the bits we're interested in.
238
+
* @return {@code true} if all of the bits are set, else {@code false}.
239
+
* @since 3.21.0
240
+
*/
241
+
publicbooleanisAllSet(finallongholder) {
242
+
return (holder & mask) == mask;
243
+
}
244
+
182
245
/**
183
246
* Tests whether the field is set or not.
184
247
* <p>
185
248
* This is most commonly used for a single-bit field, which is often used to represent a boolean value; the results of using it for a multi-bit field is to
186
-
* determine whether *any* of its bits are set.
249
+
* determine whether <em>any</em> of its bits are set.
187
250
* </p>
188
251
*
189
252
* @param holder the int data containing the bits we're interested in
@@ -193,13 +256,39 @@ public boolean isSet(final int holder) {
193
256
return (holder & mask) != 0;
194
257
}
195
258
259
+
/**
260
+
* Tests whether the field is set or not.
261
+
* <p>
262
+
* This is most commonly used for a single-bit field, which is often used to represent a boolean value; the results of using it for a multi-bit field is to
263
+
* determine whether <em>any</em> of its bits are set.
264
+
* </p>
265
+
*
266
+
* @param holder the long data containing the bits we're interested in
267
+
* @return {@code true} if any of the bits are set, else {@code false}
268
+
* @since 3.21.0
269
+
*/
270
+
publicbooleanisSet(finallongholder) {
271
+
return (holder & mask) != 0;
272
+
}
273
+
196
274
/**
197
275
* Sets the bits.
198
276
*
199
277
* @param holder the int data containing the bits we're interested in.
200
278
* @return the value of holder with the specified bits set to {@code 1}.
201
279
*/
202
280
publicintset(finalintholder) {
281
+
return (int) (holder | mask);
282
+
}
283
+
284
+
/**
285
+
* Sets the bits.
286
+
*
287
+
* @param holder the long data containing the bits we're interested in.
288
+
* @return the value of holder with the specified bits set to {@code 1}.
289
+
* @since 3.21.0
290
+
*/
291
+
publiclongset(finallongholder) {
203
292
returnholder | mask;
204
293
}
205
294
@@ -214,6 +303,18 @@ public int setBoolean(final int holder, final boolean flag) {
214
303
returnflag ? set(holder) : clear(holder);
215
304
}
216
305
306
+
/**
307
+
* Sets a boolean BitField.
308
+
*
309
+
* @param holder the long data containing the bits we're interested in.
310
+
* @param flag indicating whether to set or clear the bits.
311
+
* @return the value of holder with the specified bits set or cleared.
0 commit comments