@SuppressWarnings("unchecked")
    public void changeCapacityBy(int number) {
        int newSize = array.length + number;
        E[] temparray = (E[]) new Object[newSize];
        System.arraycopy(array, 0, temparray, 0, array.length > newSize ? newSize : array.length);
        array = temparray;

        if (lastPos > newSize - 1) {
            lastPos = newSize - 1;
            while (array[lastPos] == null && lastPos > 0) {
                --lastPos;
            }
        }
    }