LimeWire Collection Component API

org.limewire.collection
Class IntBuffer

java.lang.Object
  extended by org.limewire.collection.IntBuffer
All Implemented Interfaces:
Cloneable, Iterable<Integer>

public final class IntBuffer
extends Object
implements Cloneable, Iterable<Integer>

Provides a fixed-size double-ended queue, a circular buffer. Use IntBuffer when you want to use a fixed amount of resources. For a minimal amount of efficiency, the internal buffer is only allocated on the first insertion or retrieval, allowing lots of int buffers to be created that may not be used.

This class is not thread-safe.

    IntBuffer ib = new IntBuffer(10);
    for(int i = 0; !ib.isFull(); i++)
        ib.add(i);
    for(int i = 0; i < ib.size() ; i++)
        System.out.println(ib.get(i));      

    Output:
        9
        8
        7
        6
        5
        4
        3
        2
        1
        0


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()
           
 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 if and only if this is empty.
 boolean isFull()
          Returns true if and only if this is full, e.g., adding another element would force another out.
 org.limewire.collection.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().
 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 if and only if this is empty.


isFull

public boolean isFull()
Returns true if and only if 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 IndexOutOfBoundsException
If i<0 or i>=getSize(), throws IndexOutOfBoundsException. Else returns this[i]

Throws:
IndexOutOfBoundsException

set

public void set(int i,
                int value)
         throws IndexOutOfBoundsException
Throws:
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 NoSuchElementException
Returns the head of this, or throws NoSuchElementException if this is empty.

Throws:
NoSuchElementException

last

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

Throws:
NoSuchElementException

removeFirst

public int removeFirst()
                throws NoSuchElementException
Throws:
NoSuchElementException

removeLast

public int removeLast()
               throws NoSuchElementException
Throws:
NoSuchElementException

remove

public int remove(int i)
           throws IndexOutOfBoundsException
Throws:
IndexOutOfBoundsException

removeValue

public boolean removeValue(int x)

removeAll

public boolean removeAll(int x)

clear

public void clear()

iterator

public org.limewire.collection.IntBuffer.IntBufferIterator iterator()
Specified by:
iterator in interface Iterable<Integer>

clone

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

Overrides:
clone in class Object

toString

public String toString()
Overrides:
toString in class Object

LimeWire Collection Component API

Copyright © 2009 Lime Wire LLC. All Rights Reserved.