com.vodafone360.people.utils
Class StringBufferPool

java.lang.Object
  extended by com.vodafone360.people.utils.StringBufferPool

public class StringBufferPool
extends java.lang.Object

This is a static utility class representing the StringBuffer, pool. StringBuffer objects can be retrieved from the pool and released back to the pool when necessary. This class must to be used anywhere where String concatenation operations are intensively performed to avoid too many objects being generated and GC slowing down the performance.


Field Summary
private static java.util.ArrayList<java.lang.StringBuffer> free
          The list of free StringBuffers.
private static java.lang.Object mutex
          Synchronization.
 
Constructor Summary
private StringBufferPool()
          The constructor.
 
Method Summary
private static java.lang.StringBuffer allocStringBuffer()
           
private static java.lang.StringBuffer allocStringBuffer(java.lang.String str)
           
private static java.lang.StringBuffer getFreeStringBuffer()
           
static java.lang.StringBuffer getStringBuffer()
          This method returns a StringBuffer object from the pool...
static java.lang.StringBuffer getStringBuffer(java.lang.String str)
          This method returns a StringBuffer object from the pool...
static void releaseStringBuffer(java.lang.StringBuffer sb)
          This method calls releases the provided StringBuffer to the pool...
static java.lang.String toStringThenRelease(java.lang.StringBuffer sb)
          This method calls toString() method on the provided StringBuffer object and releases it to the pool...
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mutex

private static java.lang.Object mutex
Synchronization.


free

private static java.util.ArrayList<java.lang.StringBuffer> free
The list of free StringBuffers.

Constructor Detail

StringBufferPool

private StringBufferPool()
The constructor.

Method Detail

allocStringBuffer

private static java.lang.StringBuffer allocStringBuffer(java.lang.String str)

allocStringBuffer

private static java.lang.StringBuffer allocStringBuffer()

getFreeStringBuffer

private static java.lang.StringBuffer getFreeStringBuffer()

getStringBuffer

public static java.lang.StringBuffer getStringBuffer(java.lang.String str)
This method returns a StringBuffer object from the pool...

Parameters:
str - String - the string to initialize the StringBuffer with.
Returns:
StringBuffer object from the pool

getStringBuffer

public static java.lang.StringBuffer getStringBuffer()
This method returns a StringBuffer object from the pool...

Returns:
StringBuffer object from the pool.

releaseStringBuffer

public static void releaseStringBuffer(java.lang.StringBuffer sb)
This method calls releases the provided StringBuffer to the pool...

Parameters:
sb - StringBuffer - the StringBuffer to be released.

toStringThenRelease

public static java.lang.String toStringThenRelease(java.lang.StringBuffer sb)
This method calls toString() method on the provided StringBuffer object and releases it to the pool...

Parameters:
sb - StringBuffer - the StringBuffer to be released.
Returns:
String the toString() method result called on the provided StringBuffer.


JavaDoc