一、前言
关于flink源码包中的org.apache.flink.runtime.util.LongArrayList自定义长整型序列List,通过long[]长整型数组方式简单实现增长长度grow、删除指定序号removeLong、追加内容add等操作。
二、源码说明
package org.apache.flink.runtime.util;@b@@b@public class LongArrayList@b@{@b@ private int size;@b@ private long[] array;@b@@b@ public LongArrayList(int capacity)@b@ {@b@ this.size = 0;@b@ this.array = new long[capacity];@b@ }@b@@b@ public int size() {@b@ return this.size;@b@ }@b@@b@ public boolean add(long number) {@b@ grow(this.size + 1);@b@ this.array[(this.size++)] = number;@b@ return true;@b@ }@b@@b@ public long removeLong(int index) {@b@ if (index >= this.size)@b@ throw new IndexOutOfBoundsException("Index (" + index + ") is greater than or equal to list size (" + this.size + ")");@b@@b@ long old = this.array[index];@b@ this.size -= 1;@b@ if (index != this.size)@b@ System.arraycopy(this.array, index + 1, this.array, index, this.size - index);@b@@b@ return old;@b@ }@b@@b@ public void clear() {@b@ this.size = 0;@b@ }@b@@b@ public boolean isEmpty() {@b@ return (this.size == 0);@b@ }@b@@b@ private void grow(int length) {@b@ if (length > this.array.length) {@b@ int newLength = (int)Math.max(Math.min(2L * this.array.length, 2147483639L), length);@b@ long[] t = new long[newLength];@b@ System.arraycopy(this.array, 0, t, 0, this.size);@b@ this.array = t;@b@ }@b@ }@b@}