tisonkun commented on code in PR #1560:
URL: https://github.com/apache/incubator-fury/pull/1560#discussion_r1577300223
##########
java/fury-core/src/main/java/org/apache/fury/serializer/collection/FuryArrayAsListSerializer.java:
##########
@@ -43,4 +47,91 @@ public Collection newCollection(MemoryBuffer buffer) {
setNumElements(numElements);
return new ArrayAsList(numElements);
}
+
+ /**
+ * A List which wrap a Java array like `java.util.Arrays.ArrayList`, but
allow to replace wrapped
+ * array. Used for serialization only, do not use it in other scenarios.
+ */
+ @Internal
+ public static class ArrayAsList<E> extends AbstractList<E>
+ implements RandomAccess, java.io.Serializable {
+ private static final Object[] EMPTY = new Object[0];
+
+ private E[] array;
+ private int size;
+
+ @SuppressWarnings("unchecked")
+ public ArrayAsList(int size) {
+ array = (E[]) new Object[size];
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public boolean add(E e) {
+ array[size++] = e;
+ return true;
+ }
+
+ @Override
+ public E get(int index) {
+ return array[index];
+ }
+
+ @SuppressWarnings("unchecked")
+ public void clearArray() {
+ size = 0;
+ array = (E[]) EMPTY;
+ }
+
+ public void setArray(E[] a) {
+ array = a;
+ size = a.length;
+ }
+
+ public E[] getArray() {
+ return array;
+ }
+
+ @Override
+ public E set(int index, E element) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int indexOf(Object o) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ throw new UnsupportedOperationException();
+ }
Review Comment:
This seems to be the effective changes beyond moving the code from a
standalone file to a nested class.
But such methods are quite common and I suppose every Java developer can
write:
```java
@Override
public boolean add(E e) {
array[size++] = e;
return true;
}
@Override
public E get(int index) {
return array[index];
}
```
If such code can have compliance issues, where is the unique origin for all
the code in such pattern?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]