/** * Creates a new array with from copying oldA and removing 'length' entries at position pos. The * old array is returned to the pool. * * @param oldA old array * @param dstPos destination * @param length length * @return new array */ public static long[] arrayRemove(long[] oldA, int dstPos, int length) { long[] ret = arrayCreate(oldA.length - length); arraycopy(oldA, 0, ret, 0, dstPos); arraycopy(oldA, dstPos + length, ret, dstPos, ret.length - dstPos); POOL.offer(oldA); return ret; }
/** * Creates a new array with from copying oldA and inserting insertA at position pos. The old array * is returned to the pool. * * @param oldA old array * @param insertA array to insert * @param dstPos destination position * @return new array */ public static long[] insertArray(long[] oldA, long[] insertA, int dstPos) { long[] ret = arrayCreate(oldA.length + insertA.length); arraycopy(oldA, 0, ret, 0, dstPos); arraycopy(insertA, 0, ret, dstPos, insertA.length); arraycopy(oldA, dstPos, ret, dstPos + insertA.length, oldA.length - dstPos); POOL.offer(oldA); return ret; }
/** * Replaces an array with another array. The replaced array is returned to the pool. * * @param oldA old array * @param newA new array * @return new array */ public static long[] arrayReplace(long[] oldA, long[] newA) { if (oldA != null) { POOL.offer(oldA); } return newA; }