Methods Summary |
---|
public final void | addFirst(E e)
mHead = (mHead - 1) & mCapacityBitmask;
mElements[mHead] = e;
if (mHead == mTail) {
doubleCapacity();
}
|
public final void | addLast(E e)
mElements[mTail] = e;
mTail = (mTail + 1) & mCapacityBitmask;
if (mTail == mHead) {
doubleCapacity();
}
|
private void | doubleCapacity()
int n = mElements.length;
int r = n - mHead;
int newCapacity = n << 1;
if (newCapacity < 0) {
throw new RuntimeException("Too big");
}
Object[] a = new Object[newCapacity];
System.arraycopy(mElements, mHead, a, 0, r);
System.arraycopy(mElements, 0, a, r, mHead);
mElements = (E[])a;
mHead = 0;
mTail = n;
mCapacityBitmask = newCapacity - 1;
|
public final E | get(int i)
if (i < 0 || i >= size()) throw new ArrayIndexOutOfBoundsException();
int p = (mHead + i) & mCapacityBitmask;
return mElements[p];
|
public final E | getFirst()
if (mHead == mTail) throw new ArrayIndexOutOfBoundsException();
return mElements[mHead];
|
public final E | getLast()
if (mHead == mTail) throw new ArrayIndexOutOfBoundsException();
return mElements[(mTail - 1) & mCapacityBitmask];
|
public final boolean | isEmpty()
return mHead == mTail;
|
public final E | popFirst()
if (mHead == mTail) throw new ArrayIndexOutOfBoundsException();
E result = mElements[mHead];
mElements[mHead] = null;
mHead = (mHead + 1) & mCapacityBitmask;
return result;
|
public final E | popLast()
if (mHead == mTail) throw new ArrayIndexOutOfBoundsException();
int t = (mTail - 1) & mCapacityBitmask;
E result = mElements[t];
mElements[t] = null;
mTail = t;
return result;
|
public final int | size()
return (mTail - mHead) & mCapacityBitmask;
|