com.limegroup.gnutella.util
Class Buffer

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

public class Buffer
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
Buffer(Buffer other)
          "Copy constructor": constructs a new shallow copy of other.
Buffer(int size)
           
 
Method Summary
 java.lang.Object add(java.lang.Object x)
          Same as addFirst(x).
 java.lang.Object addFirst(java.lang.Object x)
           
 java.lang.Object addLast(java.lang.Object x)
           
 void clear()
           
 java.lang.Object clone()
          Returns a shallow copy of this, of type Buffer
 boolean contains(java.lang.Object x)
          Returns true if the input object x is in the buffer.
 java.lang.Object first()
          Returns the head of this, or throws NoSuchElementException if this is empty.
 java.lang.Object 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.
 java.util.Iterator iterator()
           
 java.lang.Object last()
          Returns the tail of this, or throws NoSuchElementException if this is empty.
 java.lang.Object remove(int i)
           
 boolean remove(java.lang.Object x)
           
 boolean removeAll(java.lang.Object x)
           
 java.lang.Object removeFirst()
           
 java.lang.Object removeLast()
           
 void set(int i, java.lang.Object o)
           
 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

Buffer

public Buffer(int size)

Buffer

public Buffer(Buffer 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 java.lang.Object 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,
                java.lang.Object o)
         throws java.lang.IndexOutOfBoundsException
Throws:
java.lang.IndexOutOfBoundsException

add

public java.lang.Object add(java.lang.Object x)
Same as addFirst(x).


addFirst

public java.lang.Object addFirst(java.lang.Object x)

addLast

public java.lang.Object addLast(java.lang.Object x)

contains

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


first

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

Throws:
java.util.NoSuchElementException

last

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

Throws:
java.util.NoSuchElementException

removeFirst

public java.lang.Object removeFirst()
                             throws java.util.NoSuchElementException
Throws:
java.util.NoSuchElementException

removeLast

public java.lang.Object removeLast()
                            throws java.util.NoSuchElementException
Throws:
java.util.NoSuchElementException

remove

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

remove

public boolean remove(java.lang.Object x)

removeAll

public boolean removeAll(java.lang.Object x)

clear

public void clear()

iterator

public java.util.Iterator iterator()

clone

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


toString

public java.lang.String toString()