Minor Improvement: (#34)
* Change 'StringBuffer' by 'StringBuilder' * Fix javadoc * Remove redundant initializer * Use Empty array
This commit is contained in:
@@ -133,7 +133,7 @@ public abstract class LogFactory {
|
||||
* generated by LogFactory or LogFactoryImpl. When non-null,
|
||||
* interesting events will be written to the specified object.
|
||||
*/
|
||||
private static PrintStream diagnosticsStream;
|
||||
private static final PrintStream DIAGNOSTICS_STREAM;
|
||||
|
||||
/**
|
||||
* A string that gets prefixed to every message output by the
|
||||
@@ -1088,7 +1088,7 @@ public abstract class LogFactory {
|
||||
// has been specified. Several well known containers use this mechanism to adapt JCL
|
||||
// to their native logging system.
|
||||
//
|
||||
final StringBuffer msg = new StringBuffer();
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
msg.append("The application has specified that a custom LogFactory implementation ");
|
||||
msg.append("should be used but Class '");
|
||||
msg.append(factoryClass);
|
||||
@@ -1503,7 +1503,7 @@ public abstract class LogFactory {
|
||||
* @since 1.1
|
||||
*/
|
||||
protected static boolean isDiagnosticsEnabled() {
|
||||
return diagnosticsStream != null;
|
||||
return DIAGNOSTICS_STREAM != null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1525,10 +1525,10 @@ public abstract class LogFactory {
|
||||
* @param msg is the diagnostic message to be output.
|
||||
*/
|
||||
private static final void logDiagnostic(final String msg) {
|
||||
if (diagnosticsStream != null) {
|
||||
diagnosticsStream.print(diagnosticPrefix);
|
||||
diagnosticsStream.println(msg);
|
||||
diagnosticsStream.flush();
|
||||
if (DIAGNOSTICS_STREAM != null) {
|
||||
DIAGNOSTICS_STREAM.print(diagnosticPrefix);
|
||||
DIAGNOSTICS_STREAM.println(msg);
|
||||
DIAGNOSTICS_STREAM.flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1539,9 +1539,9 @@ public abstract class LogFactory {
|
||||
* @since 1.1
|
||||
*/
|
||||
protected static final void logRawDiagnostic(final String msg) {
|
||||
if (diagnosticsStream != null) {
|
||||
diagnosticsStream.println(msg);
|
||||
diagnosticsStream.flush();
|
||||
if (DIAGNOSTICS_STREAM != null) {
|
||||
DIAGNOSTICS_STREAM.println(msg);
|
||||
DIAGNOSTICS_STREAM.flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1616,7 +1616,7 @@ public abstract class LogFactory {
|
||||
return;
|
||||
}
|
||||
if (classLoader != null) {
|
||||
final StringBuffer buf = new StringBuffer(prefix + "ClassLoader tree:");
|
||||
final StringBuilder buf = new StringBuilder(prefix + "ClassLoader tree:");
|
||||
for(;;) {
|
||||
buf.append(objectId(classLoader));
|
||||
if (classLoader == systemClassLoader) {
|
||||
@@ -1704,7 +1704,7 @@ public abstract class LogFactory {
|
||||
classLoaderName = "UNKNOWN";
|
||||
}
|
||||
diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
|
||||
diagnosticsStream = initDiagnostics();
|
||||
DIAGNOSTICS_STREAM = initDiagnostics();
|
||||
logClassLoaderEnvironment(LogFactory.class);
|
||||
factories = createFactoryStore();
|
||||
if (isDiagnosticsEnabled()) {
|
||||
|
||||
@@ -68,6 +68,11 @@ public class LogSource {
|
||||
/** Constructor for current log class */
|
||||
static protected Constructor logImplctor;
|
||||
|
||||
/**
|
||||
* An empty immutable {@code String} array.
|
||||
*/
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
// ----------------------------------------------------- Class Initializers
|
||||
|
||||
static {
|
||||
@@ -215,6 +220,6 @@ public class LogSource {
|
||||
* all logs known to me.
|
||||
*/
|
||||
static public String[] getLogNames() {
|
||||
return (String[]) logs.keySet().toArray(new String[logs.size()]);
|
||||
return (String[]) logs.keySet().toArray(EMPTY_STRING_ARRAY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,11 @@ public class LogFactoryImpl extends LogFactory {
|
||||
private static final String PKG_IMPL="org.apache.commons.logging.impl.";
|
||||
private static final int PKG_LEN = PKG_IMPL.length();
|
||||
|
||||
/**
|
||||
* An empty immutable {@code String} array.
|
||||
*/
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
/**
|
||||
@@ -254,7 +259,7 @@ public class LogFactoryImpl extends LogFactory {
|
||||
*/
|
||||
@Override
|
||||
public String[] getAttributeNames() {
|
||||
return (String[]) attributes.keySet().toArray(new String[attributes.size()]);
|
||||
return (String[]) attributes.keySet().toArray(EMPTY_STRING_ARRAY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1360,7 +1365,7 @@ public class LogFactoryImpl extends LogFactory {
|
||||
}
|
||||
|
||||
if (!allowFlawedHierarchy) {
|
||||
final StringBuffer msg = new StringBuffer();
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
msg.append("Terminating logging for this context ");
|
||||
msg.append("due to bad log hierarchy. ");
|
||||
msg.append("You have more than one version of '");
|
||||
@@ -1373,7 +1378,7 @@ public class LogFactoryImpl extends LogFactory {
|
||||
}
|
||||
|
||||
if (isDiagnosticsEnabled()) {
|
||||
final StringBuffer msg = new StringBuffer();
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
msg.append("Warning: bad log hierarchy. ");
|
||||
msg.append("You have more than one version of '");
|
||||
msg.append(Log.class.getName());
|
||||
@@ -1383,7 +1388,7 @@ public class LogFactoryImpl extends LogFactory {
|
||||
} else {
|
||||
// this is just a bad adapter class
|
||||
if (!allowFlawedDiscovery) {
|
||||
final StringBuffer msg = new StringBuffer();
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
msg.append("Terminating logging for this context. ");
|
||||
msg.append("Log class '");
|
||||
msg.append(badClass.getName());
|
||||
@@ -1396,7 +1401,7 @@ public class LogFactoryImpl extends LogFactory {
|
||||
}
|
||||
|
||||
if (isDiagnosticsEnabled()) {
|
||||
final StringBuffer msg = new StringBuffer();
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
msg.append("[WARNING] Log class '");
|
||||
msg.append(badClass.getName());
|
||||
msg.append("' does not implement the Log interface.");
|
||||
|
||||
@@ -86,7 +86,7 @@ public class SimpleLog implements Log, Serializable {
|
||||
static protected final String DEFAULT_DATE_TIME_FORMAT = "yyyy/MM/dd HH:mm:ss:SSS zzz";
|
||||
|
||||
/** Include the instance name in the log message? */
|
||||
static volatile protected boolean showLogName = false;
|
||||
static volatile protected boolean showLogName;
|
||||
|
||||
/** Include the short name ( last component ) of the logger in the log
|
||||
* message. Defaults to true - otherwise we'll be lost in a flood of
|
||||
@@ -95,7 +95,7 @@ public class SimpleLog implements Log, Serializable {
|
||||
static volatile protected boolean showShortName = true;
|
||||
|
||||
/** Include the current time in the log message */
|
||||
static volatile protected boolean showDateTime = false;
|
||||
static volatile protected boolean showDateTime;
|
||||
|
||||
/** The date and time format to use in the log message */
|
||||
static volatile protected String dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
|
||||
@@ -193,11 +193,11 @@ public class SimpleLog implements Log, Serializable {
|
||||
// ------------------------------------------------------------- Attributes
|
||||
|
||||
/** The name of this simple log instance */
|
||||
protected volatile String logName = null;
|
||||
protected volatile String logName;
|
||||
/** The current log level */
|
||||
protected volatile int currentLogLevel;
|
||||
/** The short name of this simple log instance */
|
||||
private volatile String shortLogName = null;
|
||||
private volatile String shortLogName;
|
||||
|
||||
// ------------------------------------------------------------ Constructor
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ public final class WeakHashtable extends Hashtable {
|
||||
/* ReferenceQueue we check for gc'd keys */
|
||||
private final ReferenceQueue queue = new ReferenceQueue();
|
||||
/* Counter used to control how often we purge gc'd entries */
|
||||
private int changeCount = 0;
|
||||
private int changeCount;
|
||||
|
||||
/**
|
||||
* Constructs a WeakHashtable with the Hashtable default
|
||||
|
||||
@@ -395,7 +395,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
/**
|
||||
*
|
||||
* Clean implementation of list function of
|
||||
* {@link java.utils.Collection} added in JDK 1.4
|
||||
* {@link java.util.Collection} added in JDK 1.4
|
||||
* @param en <code>Enumeration</code>, possibly null
|
||||
* @return <code>ArrayList</code> containing the enumerated
|
||||
* elements in the enumerated order, not null
|
||||
|
||||
Reference in New Issue
Block a user