org.mentalog.util.StringBuilderUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of menta-log Show documentation
Show all versions of menta-log Show documentation
A log library that embraces the kiss principle.
package org.mentalog.util;
import org.mentalog.Log;
/**
* This code is NOT thread-safe at all.
*
* You can use to_sb to bypass autoboxing and avoid the object creation. So intead of:
*
* Info.log(myInteger);
*
* you would do:
*
* Info.log(to_sb(myInteger));
*
* NOTE: If you want to use this from multiple threads you MUST synchronize around to_sb:
*
* synchronized(Info) { Info.log(to_sb(myInteger)); }
*
* @author Sergio Oliveira Jr.
*/
public class StringBuilderUtils {
private static volatile boolean isSynchronized;
private static ThreadLocal threadLocal;
private static final StringBuilderPool singlePool = new StringBuilderPool();
static {
threadLocal = new ThreadLocal() {
@Override
protected StringBuilderPool initialValue() {
return new StringBuilderPool();
}
};
isSynchronized = Log.isSynchronized();
}
private final static StringBuilderPool getPool() {
if (isSynchronized) {
return threadLocal.get();
} else {
return singlePool;
}
}
public final static StringBuilder to_sb(int x) {
return getPool().to_sb(x);
}
public final static StringBuilder to_sb(float x) {
return getPool().to_sb(x);
}
public final static StringBuilder to_sb(short x) {
return getPool().to_sb(x);
}
public final static StringBuilder to_sb(byte x) {
return getPool().to_sb(x);
}
public final static StringBuilder to_sb(char x) {
return getPool().to_sb(x);
}
public final static StringBuilder to_sb(boolean x) {
return getPool().to_sb(x);
}
public final static StringBuilder to_sb(long x) {
return getPool().to_sb(x);
}
public final static StringBuilder to_sb(double x) {
return getPool().to_sb(x);
}
public final static void reset() {
getPool().reset();
}
public final static int getPointer() {
return getPool().getPointer();
}
}