/**
* Used to fine tune initial StringBuilder size estimates.
* Insert a call to checkStringBuilderEstimate just before toString.
*
* @param sb the StringBuilder to check.
* @param lowSize the lowest expected size of a result with this StringBuilder.
* @param highSize usually the initial size the StringBuilder was allocated,
* the highest expected size of a result with this StringBuilder.
*/
@SuppressWarnings( { "ThrowableInstanceNeverThrown"} )
public static void checkStringBuilderEstimate( StringBuilder sb, int lowSize, int highSize )
{
final int size = sb.length();
final String different;
if ( size > highSize )
{
different = "longer";
}
else if ( size < lowSize )
{
different = "shorter";
}
else
{
return;
}
if ( Configure.USING_JET )
{
err.println( "Warning: StringBuilder length "
+ size
+ " is "
+ different
+ " from expected range "
+ lowSize
+ ".."
+ highSize
+ ". Run under Sun JVM to find out where the problem lies." );
}
else
{
StackTraceElement e = new Throwable().getStackTrace()[ 1 ];
err.println( "Warning: "
+ e.getClassName()
+ "."
+ e.getMethodName()
+ " line:" + e.getLineNumber()
+ " StringBuilder length "
+ size
+ " is "
+ different
+ " from expected range "
+ lowSize
+ ".."
+ highSize
+ "." );
}
}