chaokunyang commented on code in PR #1560:
URL: https://github.com/apache/incubator-fury/pull/1560#discussion_r1577314289


##########
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:
   I just removed the implementation of methods which won't be invoked by Fury 
currently.
   
   But to be honest, I think Java developer  will write similar code if he want 
to implement a List based on an Array.



-- 
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]

Reply via email to