-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathArrayFactory.java
More file actions
88 lines (79 loc) · 2.47 KB
/
ArrayFactory.java
File metadata and controls
88 lines (79 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package javasabr.rlib.collections.array;
import javasabr.rlib.collections.array.impl.CopyOnWriteMutableArray;
import javasabr.rlib.collections.array.impl.DefaultMutableArray;
import javasabr.rlib.collections.array.impl.DefaultMutableIntArray;
import javasabr.rlib.collections.array.impl.DefaultMutableLongArray;
import javasabr.rlib.collections.array.impl.StampedLockBasedArray;
import javasabr.rlib.common.util.ClassUtils;
import lombok.experimental.UtilityClass;
/**
* Factory for creating various array implementations.
*
* @since 10.0.0
*/
@UtilityClass
public class ArrayFactory {
/**
* Creates a new mutable array of the specified type.
*
* @param <E> the type of elements
* @param type the component type of the array
* @return a new mutable array
* @since 10.0.0
*/
public static <E> MutableArray<E> mutableArray(Class<? super E> type) {
return new DefaultMutableArray<>(ClassUtils.unsafeCast(type));
}
/**
* Creates a new mutable int array.
*
* @return a new mutable int array
* @since 10.0.0
*/
public static MutableIntArray mutableIntArray() {
return new DefaultMutableIntArray();
}
/**
* Creates a new mutable long array.
*
* @return a new mutable long array
* @since 10.0.0
*/
public static MutableLongArray mutableLongArray() {
return new DefaultMutableLongArray();
}
/**
* Creates a new mutable array of the specified type with initial capacity.
*
* @param <E> the type of elements
* @param type the component type of the array
* @param capacity the initial capacity
* @return a new mutable array
* @since 10.0.0
*/
public static <E> MutableArray<E> mutableArray(Class<? super E> type, int capacity) {
return new DefaultMutableArray<>(ClassUtils.unsafeCast(type), capacity);
}
/**
* Creates a new copy-on-modify array of the specified type.
*
* @param <E> the type of elements
* @param type the component type of the array
* @return a new copy-on-modify array
* @since 10.0.0
*/
public static <E> MutableArray<E> copyOnModifyArray(Class<? super E> type) {
return new CopyOnWriteMutableArray<>(type);
}
/**
* Creates a new thread-safe array backed by a stamped lock.
*
* @param <E> the type of elements
* @param type the component type of the array
* @return a new lockable array
* @since 10.0.0
*/
public static <E> LockableArray<E> stampedLockBasedArray(Class<? super E> type) {
return new StampedLockBasedArray<>(type);
}
}