com.limegroup.gnutella.util
Class IntBuffer

java.lang.Object
  extended bycom.limegroup.gnutella.util.IntBuffer
All Implemented Interfaces:
java.lang.Cloneable

public final class IntBuffer
extends java.lang.Object
implements java.lang.Cloneable

A very simple fixed-size double-ended queue, i.e., a circular buffer. The fixed size is intentional, not the result of laziness; use this data structure when you want to use a fix amount of resources. This is not thread-safe.


Constructor Summary
IntBuffer(int size)
           
IntBuffer(IntBuffer other)
          "Copy constructor": constructs a new shallow copy of other.
 
Method Summary
 int add(int x)
          Same as addFirst(x).
 int addFirst(int x)
           
 int addLast(int x)
           
 void clear()
           
 java.lang.Object clone()
          Returns a shallow copy of this, of type IntBuffer
 boolean contains(int x)
          Returns true if the input object x is in the buffer.
 int first()
          Returns the head of this, or throws NoSuchElementException if this is empty.
 int get(int i)
          If i<0 or i>=getSize(), throws IndexOutOfBoundsException.
 int getCapacity()
          Returns the number of elements that this can hold, i.e., the max size that was passed to the constructor.
 int getSize()
          Returns the number of elements in this.
 boolean isEmpty()
          Returns true iff this is empty.
 boolean isFull()
          Returns true iff this is full, e.g., adding another element would force another out.
 com.limegroup.gnutella.util.IntBuffer.IntBufferIterator iterator()
           
 int last()
          Returns the tail of this, or throws NoSuchElementException if this is empty.
 int remove(int i)
           
 boolean removeAll(int x)
           
 int removeFirst()
           
 int removeLast()
           
 boolean removeValue(int x)
           
 void set(int i, int value)
           
 int size()
          Same as getSize().
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntBuffer

public IntBuffer(int size)

IntBuffer

public IntBuffer(IntBuffer other)
"Copy constructor": constructs a new shallow copy of other.

Method Detail

isEmpty

public boolean isEmpty()
Returns true iff this is empty.


isFull

public boolean isFull()
Returns true iff this is full, e.g., adding another element would force another out.


size

public final int size()
Same as getSize().


getSize

public int getSize()
Returns the number of elements in this. Note that this never exceeds the value returned by getCapacity.


getCapacity

public int getCapacity()
Returns the number of elements that this can hold, i.e., the max size that was passed to the constructor.


get

public int get(int i)
        throws java.lang.IndexOutOfBoundsException
If i<0 or i>=getSize(), throws IndexOutOfBoundsException. Else returns this[i]

Throws:
java.lang.IndexOutOfBoundsException

set

public void set(int i,
                int value)
         throws java.lang.IndexOutOfBoundsException
Throws:
java.lang.IndexOutOfBoundsException

add

public int add(int x)
Same as addFirst(x).


addFirst

public int addFirst(int x)

addLast

public int addLast(int x)

contains

public boolean contains(int x)
Returns true if the input object x is in the buffer.


first

public int first()
          throws java.util.NoSuchElementException
Returns the head of this, or throws NoSuchElementException if this is empty.

Throws:
java.util.NoSuchElementException

last

public int last()
         throws java.util.NoSuchElementException
Returns the tail of this, or throws NoSuchElementException if this is empty.

Throws:
java.util.NoSuchElementException

removeFirst

public int removeFirst()
                throws java.util.NoSuchElementException
Throws:
java.util.NoSuchElementException

removeLast

public int removeLast()
               throws java.util.NoSuchElementException
Throws:
java.util.NoSuchElementException

remove

public int remove(int i)
           throws java.lang.IndexOutOfBoundsException
Throws:
java.lang.IndexOutOfBoundsException

removeValue

public boolean removeValue(int x)

removeAll

public boolean removeAll(int x)

clear

public void clear()

iterator

public com.limegroup.gnutella.util.IntBuffer.IntBufferIterator iterator()

clone

public java.lang.Object clone()
Returns a shallow copy of this, of type IntBuffer


toString

public java.lang.String toString()