Methods Summary |
---|
public final boolean | add(T item)
final int capacity = capacity();
assert( mFirst < capacity );
// if we're full before adding, then we'll be overwriting
// the first item.
if ( size() == capacity )
{
final T overwrittenObject = get( 0 );
// first item will be overwritten; next one is first (oldest)
mFirst = (mFirst + 1) % capacity;
store( capacity - 1, item );
discardedObject( overwrittenObject );
}
else
{
store( mNumItems, item );
++mNumItems;
}
++modCount;
return( true );
|
public final void | add(int index, T item)May be added to the end only.
if ( index == mNumItems )
{
add( item );
}
else
{
throw new UnsupportedOperationException( "add not at end" );
}
|
public final int | capacity()
return( mObjects.length );
|
private final void | checkInBounds(int i)
if ( i < 0 || i >= mNumItems )
{
throw new IndexOutOfBoundsException( "" + i );
}
|
public final void | clear()
for( int i = 0; i < size(); ++i )
{
set( i, null );
}
mNumItems = 0;
++modCount;
|
protected void | discardedObject(T o)
if ( mOverflowHandler != null )
{
mOverflowHandler.handleBufferOverflow( o );
}
|
public boolean | equals(java.lang.Object rhsIn)
boolean equal = false;
if ( rhsIn == this )
{
equal = true;
}
else if ( ! (rhsIn instanceof CircularList) )
{
equal = false;
}
else
{
final CircularList rhs = (CircularList)rhsIn;
equal = capacity() == rhs.capacity() &&
size() == rhs.size();
if ( equal )
{
final int size = size();
for( int i = 0; i < size(); ++i )
{
if ( ! CompareUtil.objectsEqual( get( i ), rhs.get( i ) ) )
{
equal = false;
break;
}
}
}
}
return( equal );
|
public final T | get(int i)
checkInBounds( i );
return( mObjects[ getPhysicalIndex( i ) ] );
|
public com.sun.appserv.management.util.misc.CircularList$OverflowHandler | getOverflowHandler()
return( mOverflowHandler );
|
private final int | getPhysicalIndex(int logicalIndex)
return( (mFirst + logicalIndex) % capacity() );
|
public final T | remove(int i)
T result = null;
if ( i == 0 )
{
result = removeFirst();
}
else if ( i == mNumItems - 1 )
{
result = removeLast();
}
else
{
throw new UnsupportedOperationException();
}
++modCount;
return( result );
|
public final T | removeFirst()
checkInBounds( 0 );
final T result = get( 0 );
--mNumItems;
mFirst = (mFirst + 1) % capacity();
return( result );
|
public final T | removeLast()
checkInBounds( 0 );
final T result = get( mNumItems - 1 );
--mNumItems;
return( result );
|
public final T | set(int i, T item)
checkInBounds( i );
final int physicalIndex = getPhysicalIndex( i );
final T oldItem = mObjects[ physicalIndex ];
mObjects[ physicalIndex ] = item;
return( oldItem );
|
public void | setOverflowHandler(com.sun.appserv.management.util.misc.CircularList$OverflowHandler handler)
mOverflowHandler = handler;
|
public final int | size()
return( mNumItems );
|
private final void | store(int logicalIndex, T item)
mObjects[ getPhysicalIndex( logicalIndex ) ] = item;
|
public java.lang.String | toString()
return( ArrayStringifier.stringify( toArray( ), ", " ) );
|