Skip to content

Commit 565b4a1

Browse files
committed
update array API
1 parent c144e6d commit 565b4a1

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

  • rlib-common/src/main/java/com/ss/rlib/common/util/array

rlib-common/src/main/java/com/ss/rlib/common/util/array/Array.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ public interface Array<E> extends Collection<E>, Serializable, Reusable, Cloneab
4949
}
5050

5151
/**
52-
* Wrap a native array to a read only array.
52+
* Copy an array to a read only array.
5353
*
54-
* @param elements the elements to wrap.
55-
* @param <T> the element's type.
54+
* @param another the another array.
55+
* @param <T> the element's type.
5656
* @return the new read only array.
5757
*/
58-
static <T> @NotNull ReadOnlyArray<T> of(@NotNull T[] elements) {
59-
return ArrayFactory.newReadOnlyArray(ArrayUtils.copyOf(elements));
58+
static <T> @NotNull ReadOnlyArray<T> of(@NotNull Array<T> another) {
59+
return ArrayFactory.newReadOnlyArray(ArrayUtils.copyOf(another.array(), 0, another.size()));
6060
}
6161

6262
/**
@@ -75,12 +75,8 @@ public interface Array<E> extends Collection<E>, Serializable, Reusable, Cloneab
7575
}
7676

7777
@SafeVarargs
78-
static <T> @NotNull ReadOnlyArray<T> of(@NotNull T element, @NotNull T... elements) {
79-
80-
T[] newArray = ArrayUtils.copyOf(elements, 1, 1);
81-
newArray[0] = element;
82-
83-
return ArrayFactory.newReadOnlyArray(newArray);
78+
static <T> @NotNull ReadOnlyArray<T> of(@NotNull T... elements) {
79+
return ArrayFactory.newReadOnlyArray(ArrayUtils.copyOf(elements));
8480
}
8581

8682
@SafeVarargs
@@ -114,7 +110,7 @@ public interface Array<E> extends Collection<E>, Serializable, Reusable, Cloneab
114110
* @param <T> the element's type.
115111
* @return the supplier.
116112
*/
117-
static <T> @NotNull Supplier<Array<T>> supplier(@NotNull Class<? super T> type) {
113+
static <T> @NotNull NotNullSupplier<Array<T>> supplier(@NotNull Class<? super T> type) {
118114
return () -> ArrayFactory.newConcurrentStampedLockArray(type);
119115
}
120116

@@ -125,7 +121,7 @@ public interface Array<E> extends Collection<E>, Serializable, Reusable, Cloneab
125121
* @param <T> the element's type.
126122
* @return the supplier.
127123
*/
128-
static <T> @NotNull Function<Class<? super T>, Array<T>> function(@NotNull Class<? super T> type) {
124+
static <T> @NotNull NotNullFunction<Class<? super T>, Array<T>> function(@NotNull Class<? super T> type) {
129125
return ArrayFactory::newConcurrentStampedLockArray;
130126
}
131127

0 commit comments

Comments
 (0)