4
4
*/
5
5
package org .hibernate .internal .util .collections ;
6
6
7
- import java .io .Serializable ;
8
7
import java .lang .reflect .Array ;
9
8
import java .util .ArrayList ;
10
9
import java .util .Arrays ;
11
10
import java .util .Collection ;
12
- import java .util .Iterator ;
13
11
import java .util .List ;
14
- import java .util .SortedSet ;
15
- import java .util .TreeSet ;
16
12
import java .util .function .Consumer ;
17
13
18
- import org .checkerframework .checker .nullness .qual .NonNull ;
19
- import org .hibernate .HibernateException ;
20
- import org .hibernate .LockMode ;
21
- import org .hibernate .LockOptions ;
22
14
import org .hibernate .internal .build .AllowReflection ;
23
15
import org .hibernate .type .Type ;
24
16
@@ -66,7 +58,6 @@ public static int indexOf(Object[] array, int end, Object object) {
66
58
67
59
@ SuppressWarnings ("unchecked" )
68
60
@ AllowReflection
69
- @ Deprecated (forRemoval = true , since = "7.3" )
70
61
public static <T > T [] filledArray (T value , Class <T > valueJavaType , int size ) {
71
62
final T [] array = (T []) Array .newInstance ( valueJavaType , size );
72
63
Arrays .fill ( array , value );
@@ -82,34 +73,6 @@ public static String[] toStringArray(Object[] objects) {
82
73
return result ;
83
74
}
84
75
85
- @ Deprecated (forRemoval = true , since = "7.3" )
86
- public static String [] fillArray (String value , int length ) {
87
- final var result = new String [length ];
88
- Arrays .fill ( result , value );
89
- return result ;
90
- }
91
-
92
- @ Deprecated (forRemoval = true , since = "7.3" )
93
- public static int [] fillArray (int value , int length ) {
94
- final var result = new int [length ];
95
- Arrays .fill ( result , value );
96
- return result ;
97
- }
98
-
99
- @ Deprecated (forRemoval = true , since = "7.3" )
100
- public static LockMode [] fillArray (LockMode lockMode , int length ) {
101
- final var array = new LockMode [length ];
102
- Arrays .fill ( array , lockMode );
103
- return array ;
104
- }
105
-
106
- @ Deprecated (forRemoval = true , since = "7.3" )
107
- public static LockOptions [] fillArray (LockOptions lockOptions , int length ) {
108
- final var array = new LockOptions [length ];
109
- Arrays .fill ( array , lockOptions );
110
- return array ;
111
- }
112
-
113
76
public static String [] toStringArray (Collection <String > coll ) {
114
77
return coll .toArray ( EMPTY_STRING_ARRAY );
115
78
}
@@ -150,24 +113,6 @@ public static boolean[] toBooleanArray(Collection<Boolean> coll) {
150
113
return arr ;
151
114
}
152
115
153
- @ Deprecated (forRemoval = true , since = "7.2" )
154
- public static Object [] typecast (Object [] array , Object [] to ) {
155
- return asList ( array ).toArray ( to );
156
- }
157
-
158
- //Arrays.asList doesn't do primitive arrays
159
- // public static List toList(Object array) {
160
- // if ( array instanceof Object[] ) {
161
- // return Arrays.asList( (Object[]) array ); //faster?
162
- // }
163
- // int size = Array.getLength( array );
164
- // ArrayList<Object> list = new ArrayList<>( size );
165
- // for ( int i = 0; i < size; i++ ) {
166
- // list.add( Array.get( array, i ) );
167
- // }
168
- // return list;
169
- // }
170
-
171
116
public static String [] slice (String [] strings , int begin , int length ) {
172
117
final var result = new String [length ];
173
118
System .arraycopy ( strings , begin , result , 0 , length );
@@ -180,14 +125,6 @@ public static Object[] slice(Object[] objects, int begin, int length) {
180
125
return result ;
181
126
}
182
127
183
- public static <T > List <T > toList (Iterator <T > iter ) {
184
- final List <T > list = new ArrayList <>();
185
- while ( iter .hasNext () ) {
186
- list .add ( iter .next () );
187
- }
188
- return list ;
189
- }
190
-
191
128
public static String [] join (String [] x , String [] y ) {
192
129
final var result = new String [x .length + y .length ];
193
130
System .arraycopy ( x , 0 , result , 0 , x .length );
@@ -318,155 +255,6 @@ public static <T> void addAll(Collection<T> collection, T[] array) {
318
255
public static final Type [] EMPTY_TYPE_ARRAY = {};
319
256
public static final byte [] EMPTY_BYTE_ARRAY = {};
320
257
321
- /**
322
- * Calculate the batch partitions needed to handle the {@code mappedBatchSize}.
323
- *
324
- * @param mappedBatchSize The {@link org.hibernate.annotations.BatchSize batch-size}.
325
- * Internally this is capped at {@code 256}
326
- *
327
- * @implNote The max batch size is capped at {@code 256}
328
- *
329
- * @return The upper bound for the partitions
330
- *
331
- * @deprecated No longer used
332
- */
333
- @ Deprecated (forRemoval = true , since = "7.2" )
334
- public static int [] calculateBatchPartitions (int mappedBatchSize ) {
335
- final SortedSet <Integer > partitionSizes = new TreeSet <>( Integer ::compareTo );
336
- int batchSize = Math .min ( mappedBatchSize , 256 );
337
- while ( batchSize > 1 ) {
338
- partitionSizes .add ( batchSize );
339
- batchSize = calculateNextBatchPartitionLimit ( batchSize );
340
- }
341
- return toIntArray ( partitionSizes );
342
- }
343
-
344
- @ Deprecated (forRemoval = true , since = "7.2" )
345
- private static int calculateNextBatchPartitionLimit (int batchSize ) {
346
- if ( batchSize <= 10 ) {
347
- return batchSize - 1 ; //allow 9,8,7,6,5,4,3,2,1
348
- }
349
- else if ( batchSize / 2 < 10 ) {
350
- return 10 ;
351
- }
352
- else {
353
- return batchSize / 2 ;
354
- }
355
- }
356
-
357
- @ Deprecated (forRemoval = true , since = "7.2" )
358
- public static int [] getBatchSizes (int maxBatchSize ) {
359
- int batchSize = maxBatchSize ;
360
- int n = 1 ;
361
- while ( batchSize > 1 ) {
362
- batchSize = getNextBatchSize ( batchSize );
363
- n ++;
364
- }
365
- final int [] result = new int [n ];
366
- batchSize = maxBatchSize ;
367
- for ( int i = 0 ; i < n ; i ++ ) {
368
- result [i ] = batchSize ;
369
- batchSize = getNextBatchSize ( batchSize );
370
- }
371
- return result ;
372
- }
373
-
374
- @ Deprecated (forRemoval = true , since = "7.2" )
375
- private static int getNextBatchSize (int batchSize ) {
376
- if ( batchSize <= 10 ) {
377
- return batchSize - 1 ; //allow 9,8,7,6,5,4,3,2,1
378
- }
379
- else if ( batchSize / 2 < 10 ) {
380
- return 10 ;
381
- }
382
- else {
383
- return batchSize / 2 ;
384
- }
385
- }
386
-
387
- @ Deprecated (forRemoval = true , since = "7.2" )
388
- private static final int SEED = 23 ;
389
- @ Deprecated (forRemoval = true , since = "7.2" )
390
- private static final int PRIME_NUMBER = 37 ;
391
-
392
- /**
393
- * calculate the array hash (only the first level)
394
- */
395
- @ Deprecated (forRemoval = true , since = "7.2" )
396
- public static int hash (Object [] array ) {
397
- int seed = SEED ;
398
- for ( Object element : array ) {
399
- seed = hash ( seed , element == null ? 0 : element .hashCode () );
400
- }
401
- return seed ;
402
- }
403
-
404
- /**
405
- * calculate the array hash (only the first level)
406
- */
407
- @ Deprecated (forRemoval = true , since = "7.2" )
408
- public static int hash (char [] array ) {
409
- int seed = SEED ;
410
- for ( char anArray : array ) {
411
- seed = hash ( seed , anArray );
412
- }
413
- return seed ;
414
- }
415
-
416
- /**
417
- * calculate the array hash (only the first level)
418
- */
419
- @ Deprecated (forRemoval = true , since = "7.2" )
420
- public static int hash (byte [] bytes ) {
421
- int seed = SEED ;
422
- for ( byte aByte : bytes ) {
423
- seed = hash ( seed , aByte );
424
- }
425
- return seed ;
426
- }
427
-
428
- @ Deprecated (forRemoval = true , since = "7.2" )
429
- private static int hash (int seed , int i ) {
430
- return PRIME_NUMBER * seed + i ;
431
- }
432
-
433
- @ Deprecated (forRemoval = true , since = "7.2" )
434
- public static Serializable [] extractNonNull (Serializable [] array ) {
435
- final int nonNullCount = countNonNull ( array );
436
- final var result = new Serializable [nonNullCount ];
437
- int i = 0 ;
438
- for ( Serializable element : array ) {
439
- if ( element != null ) {
440
- result [i ++] = element ;
441
- }
442
- }
443
- if ( i != nonNullCount ) {
444
- throw new HibernateException ( "Number of non-null elements varied between iterations" );
445
- }
446
- return result ;
447
- }
448
-
449
- @ Deprecated (forRemoval = true , since = "7.2" )
450
- public static int countNonNull (Serializable [] array ) {
451
- int i = 0 ;
452
- for ( Serializable element : array ) {
453
- if ( element != null ) {
454
- i ++;
455
- }
456
- }
457
- return i ;
458
- }
459
-
460
- @ Deprecated (forRemoval = true , since = "7.2" )
461
- public static int countNonNull (Object [] array ) {
462
- int i = 0 ;
463
- for ( Object element : array ) {
464
- if ( element != null ) {
465
- i ++;
466
- }
467
- }
468
- return i ;
469
- }
470
258
471
259
/**
472
260
* Reverse the elements of the incoming array
@@ -544,6 +332,10 @@ public static boolean isEmpty(Object[] array) {
544
332
return array == null || array .length == 0 ;
545
333
}
546
334
335
+ public static <T > int size (T [] array ) {
336
+ return array == null ? 0 : array .length ;
337
+ }
338
+
547
339
public static <T > void forEach (T [] array , Consumer <T > consumer ) {
548
340
if ( array != null ) {
549
341
//noinspection ForLoopReplaceableByForEach
@@ -556,14 +348,10 @@ public static <T> void forEach(T[] array, Consumer<T> consumer) {
556
348
/**
557
349
* @deprecated Use {@link Array#newInstance(Class, int)} instead.
558
350
*/
559
- @ Deprecated ( forRemoval = true , since = "7" )
351
+ @ Deprecated
560
352
@ SuppressWarnings ("unchecked" )
561
353
@ AllowReflection
562
354
public static <T > T [] newInstance (Class <T > elementType , int length ) {
563
355
return (T []) Array .newInstance ( elementType , length );
564
356
}
565
-
566
- public static <T > int size (T [] array ) {
567
- return array == null ? 0 : array .length ;
568
- }
569
357
}
0 commit comments