FileDocCategorySizeDatePackage
PackedObjectVector.javaAPI DocAndroid 5.1 API4681Thu Mar 12 22:22:10 GMT 2015android.text

PackedObjectVector

public class PackedObjectVector extends Object

Fields Summary
private int
mColumns
private int
mRows
private int
mRowGapStart
private int
mRowGapLength
private Object[]
mValues
Constructors Summary
public PackedObjectVector(int columns)

        mColumns = columns;
        mValues = EmptyArray.OBJECT;
        mRows = 0;

        mRowGapStart = 0;
        mRowGapLength = mRows;
    
Methods Summary
public voiddeleteAt(int row, int count)

        moveRowGapTo(row + count);

        mRowGapStart -= count;
        mRowGapLength += count;

        if (mRowGapLength > size() * 2)
        {
            // dump();
            // growBuffer();
        }
    
public voiddump()

        for (int i = 0; i < mRows; i++)
        {
            for (int j = 0; j < mColumns; j++)
            {
                Object val = mValues[i * mColumns + j];

                if (i < mRowGapStart || i >= mRowGapStart + mRowGapLength)
                    System.out.print(val + " ");
                else
                    System.out.print("(" + val + ") ");
            }

            System.out.print(" << \n");
        }

        System.out.print("-----\n\n");
    
public EgetValue(int row, int column)

        if (row >= mRowGapStart)
            row += mRowGapLength;

        Object value = mValues[row * mColumns + column];

        return (E) value;
    
private voidgrowBuffer()

        Object[] newvalues = ArrayUtils.newUnpaddedObjectArray(
                GrowingArrayUtils.growSize(size()) * mColumns);
        int newsize = newvalues.length / mColumns;
        int after = mRows - (mRowGapStart + mRowGapLength);

        System.arraycopy(mValues, 0, newvalues, 0, mColumns * mRowGapStart);
        System.arraycopy(mValues, (mRows - after) * mColumns, newvalues, (newsize - after) * mColumns, after * mColumns);

        mRowGapLength += newsize - mRows;
        mRows = newsize;
        mValues = newvalues;
    
public voidinsertAt(int row, E[] values)

        moveRowGapTo(row);

        if (mRowGapLength == 0)
            growBuffer();

        mRowGapStart++;
        mRowGapLength--;

        if (values == null)
            for (int i = 0; i < mColumns; i++)
                setValue(row, i, null);
        else
            for (int i = 0; i < mColumns; i++)
                setValue(row, i, values[i]);
    
private voidmoveRowGapTo(int where)

        if (where == mRowGapStart)
            return;

        if (where > mRowGapStart)
        {
            int moving = where + mRowGapLength - (mRowGapStart + mRowGapLength);

            for (int i = mRowGapStart + mRowGapLength; i < mRowGapStart + mRowGapLength + moving; i++)
            {
                int destrow = i - (mRowGapStart + mRowGapLength) + mRowGapStart;

                for (int j = 0; j < mColumns; j++)
                {
                    Object val = mValues[i * mColumns + j];

                    mValues[destrow * mColumns + j] = val;
                }
            }
        }
        else /* where < mRowGapStart */
        {
            int moving = mRowGapStart - where;

            for (int i = where + moving - 1; i >= where; i--)
            {
                int destrow = i - where + mRowGapStart + mRowGapLength - moving;

                for (int j = 0; j < mColumns; j++)
                {
                    Object val = mValues[i * mColumns + j];

                    mValues[destrow * mColumns + j] = val;
                }
            }
        }

        mRowGapStart = where;
    
public voidsetValue(int row, int column, E value)

        if (row >= mRowGapStart)
            row += mRowGapLength;

        mValues[row * mColumns + column] = value;
    
public intsize()

        return mRows - mRowGapLength;
    
public intwidth()

        return mColumns;