~param bigtype ~param type ~make IntVector.java,Int,int ~make DoubleVector.java,Double,double ~make FloatVector.java,Float,float package Utils; public class Vector { public [] buf; public int size; public Vector(int initialCap) { this.buf = new [initialCap]; this.size = 0; } public Vector() { this(8); } public int resize(int newSize) { int oldSize = size; int oldCap = buf != null ? buf.length : 0; int newCap = Math.max(oldCap, 8); while (newSize > newCap) newCap = (int)((float)newCap * 1.7f) + 1; if (newCap > oldCap) { [] newBuf = new [newCap]; if (buf != null && oldCap > 0) System.arraycopy(buf, 0, newBuf, 0, oldCap); buf = newBuf; } size = newSize; return oldSize; } public int add( v) { resize(size + 1); buf[size-1] = v; return size-1; } public int add([] data) { return add(data, 0, data.length); } public int add([] data, int off, int len) { if (off >= 0 && len > 0 && off+len <= data.length) { resize(this.size + len); System.arraycopy(data, off, this.buf, this.size-len, len); } return this.size - len; } public int addFromSelf(int off, int len) { if (off >= 0 && len > 0 && off+len <= this.size) { resize(this.size + len); System.arraycopy(this.buf, off, this.buf, this.size-len, len); } return this.size - len; } public int addTwo( a, b) { resize(size + 2); buf[size-2] = a; buf[size-1] = b; return size-2; } public int addThree( a, b, c) { resize(size + 3); buf[size-3] = a; buf[size-2] = b; buf[size-1] = c; return size-3; } public int addFour( a, b, c, d) { resize(size + 4); buf[size-4] = a; buf[size-3] = b; buf[size-2] = c; buf[size-1] = d; return size-4; } public popOr(int defaultValue) { return size > 0 ? buf[--size] : defaultValue; } public lastOr(int defaultValue) { return size > 0 ? buf[size-1] : defaultValue; } public [] copy() { [] array = new [size]; if (size > 0) System.arraycopy(this.buf, 0, array, 0, size); return array; } }