jodd.util.buffer
Class FastBuffer<E>

java.lang.Object
  extended by jodd.util.buffer.FastBuffer<E>
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.RandomAccess

public class FastBuffer<E>
extends java.lang.Object
implements java.util.RandomAccess, java.lang.Iterable<E>

Fast, fast E buffer with additional features.


Constructor Summary
FastBuffer()
          Creates a new E buffer.
FastBuffer(int size)
          Creates a new E buffer, with a buffer capacity of the specified size, in bytes.
 
Method Summary
 void add(E element)
          Adds element to buffer.
 FastBuffer<E> append(E element)
          Appends single E to buffer.
 FastBuffer<E> append(E[] array)
          Appends E array to buffer.
 FastBuffer<E> append(E[] array, int off, int len)
          Appends E array to buffer.
 FastBuffer<E> append(FastBuffer<E> buff)
          Appends another fast buffer to this one.
 E[] array(int index)
          Returns E inner array chunk at given index.
 void clear()
          Resets the buffer content.
 E get(int index)
          Returns E element at given index.
 int index()
          Returns current index of inner E array chunk.
 boolean isEmpty()
          Tests if this buffer has no elements.
 java.util.Iterator<E> iterator()
          Returns an iterator over buffer elements.
 int offset()
          Returns the offset of last used element in current inner array chunk.
 int size()
          Returns buffer size.
 E[] toArray()
          Creates E array from buffered content.
 E[] toArray(int start, int len)
          Creates E subarray from buffered content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FastBuffer

public FastBuffer()
Creates a new E buffer. The buffer capacity is initially 1024 bytes, though its size increases if necessary.


FastBuffer

public FastBuffer(int size)
Creates a new E buffer, with a buffer capacity of the specified size, in bytes.

Parameters:
size - the initial size.
Throws:
java.lang.IllegalArgumentException - if size is negative.
Method Detail

append

public FastBuffer<E> append(E[] array,
                            int off,
                            int len)
Appends E array to buffer.


append

public FastBuffer<E> append(E[] array)
Appends E array to buffer.


append

public FastBuffer<E> append(E element)
Appends single E to buffer.


append

public FastBuffer<E> append(FastBuffer<E> buff)
Appends another fast buffer to this one.


size

public int size()
Returns buffer size.


isEmpty

public boolean isEmpty()
Tests if this buffer has no elements.


index

public int index()
Returns current index of inner E array chunk. Represents the index of last used inner array chunk.


offset

public int offset()
Returns the offset of last used element in current inner array chunk.


array

public E[] array(int index)
Returns E inner array chunk at given index. May be used for iterating inner chunks in fast manner.


clear

public void clear()
Resets the buffer content.


toArray

public E[] toArray()
Creates E array from buffered content.


toArray

public E[] toArray(int start,
                   int len)
Creates E subarray from buffered content.


get

public E get(int index)
Returns E element at given index.


add

public void add(E element)
Adds element to buffer.


iterator

public java.util.Iterator<E> iterator()
Returns an iterator over buffer elements.

Specified by:
iterator in interface java.lang.Iterable<E>


Copyright © 2003-2012 Jodd Team