11package com .ss .rlib .common .util .array ;
22
3- import static com .ss .rlib .common .util .ClassUtils .unsafeCast ;
3+ import static com .ss .rlib .common .util .ClassUtils .unsafeNNCast ;
44import com .ss .rlib .common .util .ArrayUtils ;
5- import com .ss .rlib .common .util .ClassUtils ;
65import com .ss .rlib .common .util .array .impl .*;
76import org .jetbrains .annotations .NotNull ;
87
@@ -16,174 +15,87 @@ public class ArrayFactory {
1615 public static final Array <?> EMPTY_ARRAY = newReadOnlyArray (ArrayUtils .EMPTY_OBJECT_ARRAY );
1716
1817 /**
19- * Wrap arguments as an array collection..
18+ * Wrap arguments as an array collection.
2019 *
21- * @param <E> the argument's type.
2220 * @param args the elements to be wrapped.
21+ * @param <E> the element's type.
2322 * @return the new array collection with the wrapped arguments.
2423 */
2524 @ SafeVarargs
26- public static <E > Array <E > asArray (@ NotNull E ... args ) {
25+ public static <E > @ NotNull Array <E > asArray (@ NotNull E ... args ) {
2726 return new FastArray <>(args );
2827 }
2928
3029 /**
31- * Create the new array.
30+ * Create the new mutable array.
3231 *
33- * @param <E> the type parameter
3432 * @param type the type of the array.
35- * @return the new array.
33+ * @param <E> the element's type.
34+ * @return the new mutable array collection.
3635 */
37- public static <E > Array <E > newArray (@ NotNull Class <? super E > type ) {
36+ public static <E > @ NotNull Array <E > newArray (@ NotNull Class <? super E > type ) {
3837 return newUnsafeArray (type );
3938 }
4039
41- /**
42- * Create the new copy on modify array.
43- *
44- * @param <E> the element's type.
45- * @param type the element's type.
46- * @return the new array.
47- */
48- public static <E > Array <E > newCopyOnModifyArray (@ NotNull Class <? super E > type ) {
40+ public static <E > @ NotNull Array <E > newArray (@ NotNull Class <? super E > type , int capacity ) {
41+ return newUnsafeArray (type , capacity );
42+ }
43+
44+ public static <E > @ NotNull Array <E > newCopyOnModifyArray (@ NotNull Class <? super E > type ) {
4945 return new CopyOnModifyArray <>(type , 0 );
5046 }
5147
52- /**
53- * Create the new unsafe array.
54- *
55- * @param <E> the type parameter
56- * @param type the type of the array.
57- * @return the new unsafe array.
58- */
59- public static <E > UnsafeArray <E > newUnsafeArray (@ NotNull Class <? super E > type ) {
48+ public static <E > @ NotNull UnsafeArray <E > newUnsafeArray (@ NotNull Class <? super E > type ) {
6049 return new FastArray <>(type );
6150 }
6251
63- /**
64- * Create the new array.
65- *
66- * @param <E> the type parameter
67- * @param type the type of the array.
68- * @param capacity the init size of the array.
69- * @return the new array.
70- */
71- public static <E > Array <E > newArray (@ NotNull Class <? super E > type , int capacity ) {
72- return newUnsafeArray (type , capacity );
52+ public static <E > UnsafeArray <E > newUnsafeArray (@ NotNull Class <? super E > type , int capacity ) {
53+ return new FastArray <>(type , capacity );
7354 }
7455
75- /**
76- * Create a new read only array.
77- *
78- * @param <E> the element's type.
79- * @return the new read only array.
80- */
81- public static <E > ReadOnlyArray <E > newReadOnlyArray (@ NotNull E [] elements ) {
56+ public static <E > @ NotNull ReadOnlyArray <E > newReadOnlyArray (@ NotNull E [] elements ) {
8257 return new ReadOnlyFastArray <>(elements );
8358 }
8459
85- /**
86- * Creates the new unsafe array.
87- *
88- * @param <E> the type parameter
89- * @param type the type of the array.
90- * @param capacity the init size of the array.
91- * @return the new unsafe array.
92- */
93- public static <E > UnsafeArray <E > newUnsafeArray (@ NotNull Class <? super E > type , int capacity ) {
94- return new FastArray <>(type , capacity );
95- }
96-
97- /**
98- * Create the new array set.
99- *
100- * @param <E> the type parameter
101- * @param type the type of the array.
102- * @return the new array.
103- */
104- public static <E > Array <E > newArraySet (@ NotNull Class <? super E > type ) {
60+ public static <E > @ NotNull Array <E > newArraySet (@ NotNull Class <? super E > type ) {
10561 return new FastArraySet <>(type );
10662 }
10763
108- /**
109- * Create the new concurrent array.
110- *
111- * @param <E> the type parameter
112- * @param type the type of the array.
113- * @return the new array.
114- */
115- public static <E > ConcurrentArray <E > newConcurrentReentrantRWLockArray (@ NotNull Class <? super E > type ) {
64+ public static <E > @ NotNull ConcurrentArray <E > newConcurrentReentrantRWLockArray (@ NotNull Class <? super E > type ) {
11665 return new ConcurrentReentrantRWLockArray <>(type );
11766 }
11867
119- /**
120- * Create the new concurrent array set.
121- *
122- * @param <E> the type parameter
123- * @param type the type of the array.
124- * @return the new array.
125- */
126- public static <E > ConcurrentArray <E > newConcurrentReentrantRWLockArraySet (@ NotNull Class <? super E > type ) {
68+ public static <E > @ NotNull ConcurrentArray <E > newConcurrentReentrantRWLockArraySet (@ NotNull Class <? super E > type ) {
12769 return new ConcurrentReentrantRWLockArraySet <>(type );
12870 }
12971
130- /**
131- * Create the new concurrent array.
132- *
133- * @param <E> the type parameter
134- * @param type the type of the array.
135- * @return the new array.
136- */
137- public static <E > ConcurrentArray <E > newConcurrentAtomicARSWLockArray (@ NotNull Class <? super E > type ) {
72+ public static <E > @ NotNull ConcurrentArray <E > newConcurrentAtomicARSWLockArray (@ NotNull Class <? super E > type ) {
13873 return new ConcurrentAtomicARSWLockArray <>(type );
13974 }
14075
141- /**
142- * Create the new stamped lock based concurrent array.
143- *
144- * @param <E> the type parameter
145- * @param type the type of the array.
146- * @return the new array.
147- */
148- public static <E > ConcurrentArray <E > newConcurrentStampedLockArray (@ NotNull Class <? super E > type ) {
76+ public static <E > @ NotNull ConcurrentArray <E > newConcurrentStampedLockArray (@ NotNull Class <? super E > type ) {
14977 return new ConcurrentStampedLockArray <>(type );
15078 }
15179
152- /**
153- * Create the new stamped lock based concurrent array.
154- *
155- * @param array the source array.
156- * @return the new array.
157- */
158- public static <E > ConcurrentArray <E > newConcurrentStampedLockArray (E @ NotNull [] array ) {
80+ public static <E > @ NotNull ConcurrentArray <E > newConcurrentStampedLockArray (E @ NotNull [] array ) {
15981
160- Class <? super E > type = ClassUtils . unsafeNNCast (array .getClass ().getComponentType ());
82+ Class <? super E > type = unsafeNNCast (array .getClass ().getComponentType ());
16183
16284 var result = new ConcurrentStampedLockArray <E >(type , array .length );
16385 result .addAll (array );
16486
16587 return result ;
16688 }
16789
168- /**
169- * Create the new sorted array.
170- *
171- * @param <E> the type parameter
172- * @param type the type of the array.
173- * @return the new array.
174- */
175- public static <E extends Comparable <E >> Array <E > newSortedArray (@ NotNull Class <? super E > type ) {
176- return new SortedArray <>(unsafeCast (type ));
90+ public static <E > @ NotNull ConcurrentArray <E > newConcurrentStampedLockArraySet (@ NotNull Class <? super E > type ) {
91+ return new ConcurrentStampedLockArraySet <>(type );
17792 }
17893
179- /**
180- * Create the new synchronized array.
181- *
182- * @param <E> the type parameter
183- * @param type the type of the array.
184- * @return the new array.
185- */
186- public static <E > Array <E > newSynchronizedArray (@ NotNull Class <? super E > type ) {
94+ public static <E extends Comparable <E >> @ NotNull Array <E > newSortedArray (@ NotNull Class <? super E > type ) {
95+ return new SortedFastArray <>(unsafeNNCast (type ));
96+ }
97+
98+ public static <E > @ NotNull Array <E > newSynchronizedArray (@ NotNull Class <? super E > type ) {
18799 return new SynchronizedArray <>(type );
188100 }
189101
@@ -199,77 +111,30 @@ public static <E> Array<E> newSynchronizedArray(@NotNull Class<? super E> type)
199111 return new DefaultIntegerArray (numbers );
200112 }
201113
202- /**
203- * Create the a long array.
204- *
205- * @return the new array.
206- */
207114 public static @ NotNull LongArray newLongArray () {
208115 return new FastLongArray ();
209116 }
210117
211- /**
212- * Create the a long array.
213- *
214- * @param capacity the init size of the array.
215- * @return the new array.
216- */
217118 public static @ NotNull LongArray newLongArray (int capacity ) {
218119 return new FastLongArray (capacity );
219120 }
220121
221- /**
222- * Create a new float array.
223- *
224- * @param elements the elements of the new float array.
225- * @return the new float array.
226- * @since 8.1.0
227- */
228122 public static @ NotNull float [] toFloatArray (float ... elements ) {
229123 return elements ;
230124 }
231125
232- /**
233- * Create a new int array.
234- *
235- * @param elements the elements of the new int array.
236- * @return the new int array.
237- * @since 8.1.0
238- */
239126 public static @ NotNull int [] toIntArray (int ... elements ) {
240127 return elements ;
241128 }
242129
243- /**
244- * Create a new long array.
245- *
246- * @param elements the elements of the new long array.
247- * @return the new long array.
248- * @since 9.0.3
249- */
250130 public static @ NotNull long [] toLongArray (long ... elements ) {
251131 return elements ;
252132 }
253133
254- /**
255- * Create a new boolean array.
256- *
257- * @param elements the elements of the new boolean array.
258- * @return the new boolean array.
259- * @since 9.2.1
260- */
261134 public static @ NotNull boolean [] toBooleanArray (boolean ... elements ) {
262135 return elements ;
263136 }
264137
265- /**
266- * Create a new object array.
267- *
268- * @param <T> the base array's element type.
269- * @param <K> the array's element type.
270- * @param elements the elements of the new array.
271- * @return the new array.
272- */
273138 @ SafeVarargs
274139 public static <T , K extends T > @ NotNull T [] toArray (K ... elements ) {
275140 return elements ;
0 commit comments