mirror of https://github.com/qos-ch/slf4j
upgrading code to Java 8
- for each - diamond operator - some typos Signed-off-by: Davide Angelocola <davide.angelocola@gmail.com>
This commit is contained in:
parent
9bc0152371
commit
c7d79d86a9
|
|
@ -32,7 +32,7 @@ public class StringPrintStream extends PrintStream {
|
|||
|
||||
public static final String LINE_SEP = System.getProperty("line.separator");
|
||||
PrintStream other;
|
||||
List<String> stringList = new ArrayList<String>();
|
||||
List<String> stringList = new ArrayList<>();
|
||||
|
||||
public StringPrintStream(PrintStream ps) {
|
||||
super(ps);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import junit.framework.TestCase;
|
|||
|
||||
public class Issue324Test extends TestCase {
|
||||
|
||||
public void testLoggerCreationInPresenseOfSecurityManager() {
|
||||
public void testLoggerCreationInPresenceOfSecurityManager() {
|
||||
String currentDir = System.getProperty("user.dir");
|
||||
System.out.println("currentDir:" + currentDir);
|
||||
Logger logger = LoggerFactory.getLogger(Issue324Test.class);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import org.osgi.framework.BundleListener;
|
|||
|
||||
public class CheckingBundleListener implements BundleListener {
|
||||
|
||||
List<BundleEvent> eventList = new ArrayList<BundleEvent>();
|
||||
List<BundleEvent> eventList = new ArrayList<>();
|
||||
|
||||
public void bundleChanged(BundleEvent be) {
|
||||
eventList.add(be);
|
||||
|
|
@ -45,16 +45,14 @@ public class CheckingBundleListener implements BundleListener {
|
|||
}
|
||||
|
||||
public void dumpAll() {
|
||||
for (int i = 0; i < eventList.size(); i++) {
|
||||
BundleEvent fe = (BundleEvent) eventList.get(i);
|
||||
for (BundleEvent fe : eventList) {
|
||||
dump(fe);
|
||||
}
|
||||
}
|
||||
|
||||
boolean exists(String bundleName) {
|
||||
for (int i = 0; i < eventList.size(); i++) {
|
||||
BundleEvent fe = (BundleEvent) eventList.get(i);
|
||||
Bundle b = fe.getBundle();
|
||||
for (BundleEvent bundleEvent : eventList) {
|
||||
Bundle b = bundleEvent.getBundle();
|
||||
System.out.println("===[" + b + "]");
|
||||
if (bundleName.equals(b.getSymbolicName())) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public class FelixHost {
|
|||
try {
|
||||
// Create host activator;
|
||||
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
List<Object> list = new ArrayList<>();
|
||||
|
||||
// list.add(new HostActivator());
|
||||
configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.xml.sax, org.xml.sax.helpers, javax.xml.parsers, javax.naming");
|
||||
|
|
|
|||
|
|
@ -32,8 +32,9 @@ import org.osgi.framework.FrameworkListener;
|
|||
|
||||
public class FrameworkErrorListener implements FrameworkListener {
|
||||
|
||||
public List<FrameworkEvent> errorList = new ArrayList<FrameworkEvent>();
|
||||
public List<FrameworkEvent> errorList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void frameworkEvent(FrameworkEvent fe) {
|
||||
if (fe.getType() == FrameworkEvent.ERROR) {
|
||||
errorList.add(fe);
|
||||
|
|
@ -54,9 +55,8 @@ public class FrameworkErrorListener implements FrameworkListener {
|
|||
}
|
||||
|
||||
public void dumpAll() {
|
||||
for (int i = 0; i < errorList.size(); i++) {
|
||||
FrameworkEvent fe = (FrameworkEvent) errorList.get(i);
|
||||
dump(fe);
|
||||
for (FrameworkEvent frameworkEvent : errorList) {
|
||||
dump(frameworkEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class SLF4JLogFactory extends LogFactory {
|
|||
* Public no-arguments constructor required by the lookup mechanism.
|
||||
*/
|
||||
public SLF4JLogFactory() {
|
||||
loggerMap = new ConcurrentHashMap<String, Log>();
|
||||
loggerMap = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- Manifest Constants
|
||||
|
|
@ -105,7 +105,7 @@ public class SLF4JLogFactory extends LogFactory {
|
|||
@SuppressWarnings("unchecked")
|
||||
public String[] getAttributeNames() {
|
||||
|
||||
List<String> names = new ArrayList<String>();
|
||||
List<String> names = new ArrayList<>();
|
||||
Enumeration<String> keys = attributes.keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
names.add((String) keys.nextElement());
|
||||
|
|
|
|||
|
|
@ -673,15 +673,13 @@ public class SimpleLog implements Log, Serializable {
|
|||
}
|
||||
|
||||
private static InputStream getResourceAsStream(final String name) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
|
||||
public InputStream run() {
|
||||
ClassLoader threadCL = getContextClassLoader();
|
||||
return AccessController.doPrivileged((PrivilegedAction<InputStream>) () -> {
|
||||
ClassLoader threadCL = getContextClassLoader();
|
||||
|
||||
if (threadCL != null) {
|
||||
return threadCL.getResourceAsStream(name);
|
||||
} else {
|
||||
return ClassLoader.getSystemResourceAsStream(name);
|
||||
}
|
||||
if (threadCL != null) {
|
||||
return threadCL.getResourceAsStream(name);
|
||||
} else {
|
||||
return ClassLoader.getSystemResourceAsStream(name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,9 +143,9 @@ public class SLF4JBridgeHandler extends Handler {
|
|||
public static void uninstall() throws SecurityException {
|
||||
java.util.logging.Logger rootLogger = getRootLogger();
|
||||
Handler[] handlers = rootLogger.getHandlers();
|
||||
for (int i = 0; i < handlers.length; i++) {
|
||||
if (handlers[i] instanceof SLF4JBridgeHandler) {
|
||||
rootLogger.removeHandler(handlers[i]);
|
||||
for (Handler handler : handlers) {
|
||||
if (handler instanceof SLF4JBridgeHandler) {
|
||||
rootLogger.removeHandler(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -153,14 +153,14 @@ public class SLF4JBridgeHandler extends Handler {
|
|||
/**
|
||||
* Returns true if SLF4JBridgeHandler has been previously installed, returns false otherwise.
|
||||
*
|
||||
* @return true if SLF4JBridgeHandler is already installed, false other wise
|
||||
* @return true if SLF4JBridgeHandler is already installed, false otherwise
|
||||
*
|
||||
*/
|
||||
public static boolean isInstalled() {
|
||||
java.util.logging.Logger rootLogger = getRootLogger();
|
||||
Handler[] handlers = rootLogger.getHandlers();
|
||||
for (int i = 0; i < handlers.length; i++) {
|
||||
if (handlers[i] instanceof SLF4JBridgeHandler) {
|
||||
for (Handler handler : handlers) {
|
||||
if (handler instanceof SLF4JBridgeHandler) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import org.apache.log4j.spi.LoggingEvent;
|
|||
|
||||
public class ListAppender extends AppenderSkeleton {
|
||||
|
||||
public List<LoggingEvent> list = new ArrayList<LoggingEvent>();
|
||||
public List<LoggingEvent> list = new ArrayList<>();
|
||||
|
||||
public boolean extractLocationInfo = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ public class SLF4JBridgeHandlerPerfTest {
|
|||
fileAppender = new FileAppender(new PatternLayout("%r [%t] %p %c %x - %m%n"), "target/test-output/toto.log");
|
||||
|
||||
existingHandlers = julRootLogger.getHandlers();
|
||||
for (int i = 0; i < existingHandlers.length; i++) {
|
||||
julRootLogger.removeHandler(existingHandlers[i]);
|
||||
for (Handler existingHandler : existingHandlers) {
|
||||
julRootLogger.removeHandler(existingHandler);
|
||||
}
|
||||
log4jRoot = org.apache.log4j.Logger.getRootLogger();
|
||||
log4jRoot.addAppender(fileAppender);
|
||||
|
|
@ -68,8 +68,8 @@ public class SLF4JBridgeHandlerPerfTest {
|
|||
SLF4JBridgeHandler.uninstall();
|
||||
fileAppender.close();
|
||||
log4jRoot.getLoggerRepository().resetConfiguration();
|
||||
for (int i = 0; i < existingHandlers.length; i++) {
|
||||
julRootLogger.addHandler(existingHandlers[i]);
|
||||
for (Handler existingHandler : existingHandlers) {
|
||||
julRootLogger.addHandler(existingHandler);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public class SLF4JBridgeHandlerTest {
|
|||
|
||||
julResourceBundleLogger.info(msg);
|
||||
assertEquals(1, listAppender.list.size());
|
||||
LoggingEvent le = (LoggingEvent) listAppender.list.get(0);
|
||||
LoggingEvent le = listAppender.list.get(0);
|
||||
assertEquals(LOGGER_NAME, le.getLoggerName());
|
||||
assertEquals(expectedMsg, le.getMessage());
|
||||
}
|
||||
|
|
@ -149,19 +149,19 @@ public class SLF4JBridgeHandlerTest {
|
|||
|
||||
LoggingEvent le = null;
|
||||
|
||||
le = (LoggingEvent) listAppender.list.get(0);
|
||||
le = listAppender.list.get(0);
|
||||
assertEquals("foo", le.getLoggerName());
|
||||
assertEquals(expectedMsg1, le.getMessage());
|
||||
|
||||
le = (LoggingEvent) listAppender.list.get(1);
|
||||
le = listAppender.list.get(1);
|
||||
assertEquals("foo", le.getLoggerName());
|
||||
assertEquals(expectedMsg2, le.getMessage());
|
||||
|
||||
le = (LoggingEvent) listAppender.list.get(2);
|
||||
le = listAppender.list.get(2);
|
||||
assertEquals("foo", le.getLoggerName());
|
||||
assertEquals(expectedMsg3, le.getMessage());
|
||||
|
||||
le = (LoggingEvent) listAppender.list.get(3);
|
||||
le = listAppender.list.get(3);
|
||||
assertEquals("yay", le.getLoggerName());
|
||||
assertEquals(expectedMsg3, le.getMessage());
|
||||
}
|
||||
|
|
@ -173,7 +173,7 @@ public class SLF4JBridgeHandlerTest {
|
|||
julLogger.logp(Level.INFO, "SLF4JBridgeHandlerTest", "testLogWithPlaceholderNoParameters", msg, new Object[0]);
|
||||
|
||||
assertEquals(1, listAppender.list.size());
|
||||
LoggingEvent le = (LoggingEvent) listAppender.list.get(0);
|
||||
LoggingEvent le = listAppender.list.get(0);
|
||||
assertEquals(LOGGER_NAME, le.getLoggerName());
|
||||
assertEquals(msg, le.getMessage());
|
||||
}
|
||||
|
|
@ -187,7 +187,7 @@ public class SLF4JBridgeHandlerTest {
|
|||
|
||||
julLogger.log(Level.INFO, msg, "ignored parameter due to IllegalArgumentException");
|
||||
assertEquals(1, listAppender.list.size());
|
||||
LoggingEvent le = (LoggingEvent) listAppender.list.get(0);
|
||||
LoggingEvent le = listAppender.list.get(0);
|
||||
assertEquals(msg, le.getMessage());
|
||||
}
|
||||
|
||||
|
|
@ -197,12 +197,12 @@ public class SLF4JBridgeHandlerTest {
|
|||
String msg = null;
|
||||
julLogger.log(Level.INFO, msg);
|
||||
assertEquals(1, listAppender.list.size());
|
||||
LoggingEvent le = (LoggingEvent) listAppender.list.get(0);
|
||||
LoggingEvent le = listAppender.list.get(0);
|
||||
assertEquals("", le.getMessage());
|
||||
}
|
||||
|
||||
void assertLevel(int index, org.apache.log4j.Level expectedLevel) {
|
||||
LoggingEvent le = (LoggingEvent) listAppender.list.get(index);
|
||||
LoggingEvent le = listAppender.list.get(index);
|
||||
assertEquals(expectedLevel, le.getLevel());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import java.util.concurrent.ConcurrentMap;
|
|||
class Log4jLoggerFactory {
|
||||
|
||||
// String, Logger
|
||||
private static ConcurrentMap<String, Logger> log4jLoggers = new ConcurrentHashMap<String, Logger>();
|
||||
private static ConcurrentMap<String, Logger> log4jLoggers = new ConcurrentHashMap<>();
|
||||
|
||||
public static Logger getLogger(String name) {
|
||||
org.apache.log4j.Logger instance = log4jLoggers.get(name);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import java.util.logging.LogRecord;
|
|||
|
||||
public class ListHandler extends Handler {
|
||||
|
||||
List<LogRecord> list = new ArrayList<LogRecord>();
|
||||
List<LogRecord> list = new ArrayList<>();
|
||||
|
||||
public void close() throws SecurityException {
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ import org.slf4j.spi.NOPLoggingEventBuilder;
|
|||
* oldT = t;
|
||||
* t = temperature;
|
||||
* <span style="color:green">logger.debug("Temperature set to {}. Old temperature was {}.", t, oldT);</span>
|
||||
* if(temperature.intValue() > 50) {
|
||||
* if (temperature.intValue() > 50) {
|
||||
* <span style="color:green">logger.info("Temperature has risen above 50 degrees.");</span>
|
||||
* }
|
||||
* }
|
||||
|
|
@ -106,7 +106,7 @@ public interface Logger {
|
|||
* @since 2.0
|
||||
*/
|
||||
default public LoggingEventBuilder makeLoggingEventBuilder(Level level) {
|
||||
if(isEnabledForLevel(level)) {
|
||||
if (isEnabledForLevel(level)) {
|
||||
return new DefaultLoggingEventBuilder(this, level);
|
||||
} else {
|
||||
return NOPLoggingEventBuilder.singleton();
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ import java.util.Set;
|
|||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import org.slf4j.event.SubstituteLoggingEvent;
|
||||
import org.slf4j.helpers.NOPLoggerFactory;
|
||||
import org.slf4j.helpers.NOP_FallbackServiceProvider;
|
||||
import org.slf4j.helpers.SubstituteServiceProvider;
|
||||
import org.slf4j.helpers.SubstituteLogger;
|
||||
|
|
@ -101,7 +100,7 @@ public final class LoggerFactory {
|
|||
|
||||
private static List<SLF4JServiceProvider> findServiceProviders() {
|
||||
ServiceLoader<SLF4JServiceProvider> serviceLoader = ServiceLoader.load(SLF4JServiceProvider.class);
|
||||
List<SLF4JServiceProvider> providerList = new ArrayList<SLF4JServiceProvider>();
|
||||
List<SLF4JServiceProvider> providerList = new ArrayList<>();
|
||||
for (SLF4JServiceProvider provider : serviceLoader) {
|
||||
providerList.add(provider);
|
||||
}
|
||||
|
|
@ -189,7 +188,7 @@ public final class LoggerFactory {
|
|||
// use Set instead of list in order to deal with bug #138
|
||||
// LinkedHashSet appropriate here because it preserves insertion order
|
||||
// during iteration
|
||||
Set<URL> staticLoggerBinderPathSet = new LinkedHashSet<URL>();
|
||||
Set<URL> staticLoggerBinderPathSet = new LinkedHashSet<>();
|
||||
try {
|
||||
ClassLoader loggerFactoryClassLoader = LoggerFactory.class.getClassLoader();
|
||||
Enumeration<URL> paths;
|
||||
|
|
@ -236,7 +235,7 @@ public final class LoggerFactory {
|
|||
final int queueSize = queue.size();
|
||||
int count = 0;
|
||||
final int maxDrain = 128;
|
||||
List<SubstituteLoggingEvent> eventList = new ArrayList<SubstituteLoggingEvent>(maxDrain);
|
||||
List<SubstituteLoggingEvent> eventList = new ArrayList<>(maxDrain);
|
||||
while (true) {
|
||||
int numDrained = queue.drainTo(eventList, maxDrain);
|
||||
if (numDrained == 0)
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ public enum Level {
|
|||
|
||||
ERROR(ERROR_INT, "ERROR"), WARN(WARN_INT, "WARN"), INFO(INFO_INT, "INFO"), DEBUG(DEBUG_INT, "DEBUG"), TRACE(TRACE_INT, "TRACE");
|
||||
|
||||
private int levelInt;
|
||||
private String levelStr;
|
||||
private final int levelInt;
|
||||
private final String levelStr;
|
||||
|
||||
Level(int i, String s) {
|
||||
levelInt = i;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ package org.slf4j.helpers;
|
|||
import org.slf4j.spi.MDCAdapter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Basic MDC implementation, which can be used with logging systems that lack
|
||||
|
|
@ -50,7 +49,7 @@ public class BasicMDCAdapter implements MDCAdapter {
|
|||
if (parentValue == null) {
|
||||
return null;
|
||||
}
|
||||
return new HashMap<String, String>(parentValue);
|
||||
return new HashMap<>(parentValue);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -72,7 +71,7 @@ public class BasicMDCAdapter implements MDCAdapter {
|
|||
}
|
||||
Map<String, String> map = inheritableThreadLocal.get();
|
||||
if (map == null) {
|
||||
map = new HashMap<String, String>();
|
||||
map = new HashMap<>();
|
||||
inheritableThreadLocal.set(map);
|
||||
}
|
||||
map.put(key, val);
|
||||
|
|
@ -134,7 +133,7 @@ public class BasicMDCAdapter implements MDCAdapter {
|
|||
public Map<String, String> getCopyOfContextMap() {
|
||||
Map<String, String> oldMap = inheritableThreadLocal.get();
|
||||
if (oldMap != null) {
|
||||
return new HashMap<String, String>(oldMap);
|
||||
return new HashMap<>(oldMap);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -142,8 +141,8 @@ public class BasicMDCAdapter implements MDCAdapter {
|
|||
|
||||
public void setContextMap(Map<String, String> contextMap) {
|
||||
Map<String, String> copy = null;
|
||||
if(contextMap != null) {
|
||||
copy = new HashMap<String, String>(contextMap);
|
||||
if (contextMap != null) {
|
||||
copy = new HashMap<>(contextMap);
|
||||
}
|
||||
inheritableThreadLocal.set(copy);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class BasicMarker implements Marker {
|
|||
|
||||
private static final long serialVersionUID = -2849567615646933777L;
|
||||
private final String name;
|
||||
private List<Marker> referenceList = new CopyOnWriteArrayList<Marker>();
|
||||
private List<Marker> referenceList = new CopyOnWriteArrayList<>();
|
||||
|
||||
BasicMarker(String name) {
|
||||
if (name == null) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import org.slf4j.Marker;
|
|||
*/
|
||||
public class BasicMarkerFactory implements IMarkerFactory {
|
||||
|
||||
private final ConcurrentMap<String, Marker> markerMap = new ConcurrentHashMap<String, Marker>();
|
||||
private final ConcurrentMap<String, Marker> markerMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Regular users should <em>not</em> create
|
||||
|
|
|
|||
|
|
@ -216,13 +216,13 @@ final public class MessageFormatter {
|
|||
// itself escaped: "abc x:\\{}"
|
||||
// we have to consume one backward slash
|
||||
sbuf.append(messagePattern, i, j - 1);
|
||||
deeplyAppendParameter(sbuf, argArray[L], new HashMap<Object[], Object>());
|
||||
deeplyAppendParameter(sbuf, argArray[L], new HashMap<>());
|
||||
i = j + 2;
|
||||
}
|
||||
} else {
|
||||
// normal case
|
||||
sbuf.append(messagePattern, i, j);
|
||||
deeplyAppendParameter(sbuf, argArray[L], new HashMap<Object[], Object>());
|
||||
deeplyAppendParameter(sbuf, argArray[L], new HashMap<>());
|
||||
i = j + 2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ public class SubstituteLoggerFactory implements ILoggerFactory {
|
|||
|
||||
volatile boolean postInitialization = false;
|
||||
|
||||
final Map<String, SubstituteLogger> loggers = new ConcurrentHashMap<String, SubstituteLogger>();
|
||||
final Map<String, SubstituteLogger> loggers = new ConcurrentHashMap<>();
|
||||
|
||||
final LinkedBlockingQueue<SubstituteLoggingEvent> eventQueue = new LinkedBlockingQueue<SubstituteLoggingEvent>();
|
||||
final LinkedBlockingQueue<SubstituteLoggingEvent> eventQueue = new LinkedBlockingQueue<>();
|
||||
|
||||
synchronized public Logger getLogger(String name) {
|
||||
SubstituteLogger logger = loggers.get(name);
|
||||
|
|
@ -58,11 +58,11 @@ public class SubstituteLoggerFactory implements ILoggerFactory {
|
|||
}
|
||||
|
||||
public List<String> getLoggerNames() {
|
||||
return new ArrayList<String>(loggers.keySet());
|
||||
return new ArrayList<>(loggers.keySet());
|
||||
}
|
||||
|
||||
public List<SubstituteLogger> getLoggers() {
|
||||
return new ArrayList<SubstituteLogger>(loggers.values());
|
||||
return new ArrayList<>(loggers.values());
|
||||
}
|
||||
|
||||
public LinkedBlockingQueue<SubstituteLoggingEvent> getEventQueue() {
|
||||
|
|
|
|||
|
|
@ -114,8 +114,8 @@ public class DoubleCheckedInt {
|
|||
|
||||
private static int[] getStateCount(StateAccessingThread[] threads) {
|
||||
int[] valCount = new int[NUMBER_OF_STATES];
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
int val = threads[i].state;
|
||||
for (StateAccessingThread thread : threads) {
|
||||
int val = thread.state;
|
||||
valCount[val] = valCount[val] + 1;
|
||||
}
|
||||
return valCount;
|
||||
|
|
|
|||
|
|
@ -83,22 +83,16 @@ public class MDCAdapterTestBase {
|
|||
@Test
|
||||
public void testMDCInheritsValuesFromParentThread() throws Exception {
|
||||
mdc.put("parentKey", "parentValue");
|
||||
runAndWait(new Runnable() {
|
||||
public void run() {
|
||||
mdc.put("childKey", "childValue");
|
||||
assertEquals("parentValue", mdc.get("parentKey"));
|
||||
}
|
||||
runAndWait(() -> {
|
||||
mdc.put("childKey", "childValue");
|
||||
assertEquals("parentValue", mdc.get("parentKey"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMDCDoesntGetValuesFromChildThread() throws Exception {
|
||||
mdc.put("parentKey", "parentValue");
|
||||
runAndWait(new Runnable() {
|
||||
public void run() {
|
||||
mdc.put("childKey", "childValue");
|
||||
}
|
||||
});
|
||||
runAndWait(() -> mdc.put("childKey", "childValue"));
|
||||
assertEquals("parentValue", mdc.get("parentKey"));
|
||||
assertNull(mdc.get("childKey"));
|
||||
}
|
||||
|
|
@ -112,17 +106,15 @@ public class MDCAdapterTestBase {
|
|||
@Test
|
||||
public void testMDCChildThreadCanOverwriteParentThread() throws Exception {
|
||||
mdc.put("sharedKey", "parentValue");
|
||||
runAndWait(new Runnable() {
|
||||
public void run() {
|
||||
assertEquals("parentValue", mdc.get("sharedKey"));
|
||||
mdc.put("sharedKey", "childValue");
|
||||
assertEquals("childValue", mdc.get("sharedKey"));
|
||||
}
|
||||
runAndWait(() -> {
|
||||
assertEquals("parentValue", mdc.get("sharedKey"));
|
||||
mdc.put("sharedKey", "childValue");
|
||||
assertEquals("childValue", mdc.get("sharedKey"));
|
||||
});
|
||||
assertEquals("parentValue", mdc.get("sharedKey"));
|
||||
}
|
||||
|
||||
private void runAndWait(Runnable runnable) throws Exception {
|
||||
private void runAndWait(Runnable runnable) {
|
||||
RecordingExceptionHandler handler = new RecordingExceptionHandler();
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.setUncaughtExceptionHandler(handler);
|
||||
|
|
@ -139,6 +131,7 @@ public class MDCAdapterTestBase {
|
|||
private static class RecordingExceptionHandler implements UncaughtExceptionHandler {
|
||||
private Throwable exception;
|
||||
|
||||
@Override
|
||||
public void uncaughtException(Thread t, Throwable e) {
|
||||
exception = e;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class StringPrintStream extends PrintStream {
|
|||
PrintStream other;
|
||||
boolean duplicate = false;
|
||||
|
||||
public List<String> stringList = Collections.synchronizedList(new ArrayList<String>());
|
||||
public List<String> stringList = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
public StringPrintStream(PrintStream ps, boolean duplicate) {
|
||||
super(ps);
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ public class SubstitutableLoggerTest {
|
|||
|
||||
// WARNING: if you need to add an excluded method to have tests pass, ask yourself whether you
|
||||
// forgot to implement the said method with delegation in SubstituteLogger. You probably did.
|
||||
private static final Set<String> EXCLUDED_METHODS = new HashSet<String>(
|
||||
Arrays.asList("getName"));
|
||||
private static final Set<String> EXCLUDED_METHODS = new HashSet<>(
|
||||
Arrays.asList("getName"));
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -85,7 +85,7 @@ public class SubstitutableLoggerTest {
|
|||
}
|
||||
|
||||
private static Set<String> determineMethodSignatures(Class<Logger> loggerClass) {
|
||||
Set<String> methodSignatures = new HashSet<String>();
|
||||
Set<String> methodSignatures = new HashSet<>();
|
||||
// Note: Class.getDeclaredMethods() does not include inherited methods
|
||||
for (Method m : loggerClass.getDeclaredMethods()) {
|
||||
if (!EXCLUDED_METHODS.contains(m.getName())) {
|
||||
|
|
@ -98,7 +98,7 @@ public class SubstitutableLoggerTest {
|
|||
|
||||
// implements InvocationHandler
|
||||
private class LoggerInvocationHandler implements InvocationHandler {
|
||||
private final Set<String> invokedMethodSignatures = new HashSet<String>();
|
||||
private final Set<String> invokedMethodSignatures = new HashSet<>();
|
||||
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
invokedMethodSignatures.add(method.toString());
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@ public class SubstituteLoggerFactoryTest {
|
|||
factory.getLogger("foo1");
|
||||
factory.getLogger("foo2");
|
||||
|
||||
Set<String> expectedNames = new HashSet<String>(Arrays.asList("foo1", "foo2"));
|
||||
Set<String> actualNames = new HashSet<String>(factory.getLoggerNames());
|
||||
Set<String> expectedNames = new HashSet<>(Arrays.asList("foo1", "foo2"));
|
||||
Set<String> actualNames = new HashSet<>(factory.getLoggerNames());
|
||||
|
||||
assertEquals(expectedNames, actualNames);
|
||||
}
|
||||
|
|
@ -63,9 +63,9 @@ public class SubstituteLoggerFactoryTest {
|
|||
factory.getLogger("foo1");
|
||||
factory.getLogger("foo2");
|
||||
|
||||
Set<String> expectedNames = new HashSet<String>(Arrays.asList("foo1", "foo2"));
|
||||
Set<String> expectedNames = new HashSet<>(Arrays.asList("foo1", "foo2"));
|
||||
|
||||
Set<String> actualNames = new HashSet<String>();
|
||||
Set<String> actualNames = new HashSet<>();
|
||||
for (SubstituteLogger slog : factory.getLoggers()) {
|
||||
actualNames.add(slog.getName());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class RunInNewThreadRule implements TestRule {
|
|||
public Statement apply(Statement base, Description description) {
|
||||
RunInNewThread desiredAnnotaton = description.getAnnotation(RunInNewThread.class);
|
||||
|
||||
if(desiredAnnotaton == null) {
|
||||
if (desiredAnnotaton == null) {
|
||||
System.out.println("test "+ description.getMethodName() +" not annotated");
|
||||
return base;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class RunInNewThreadStatement extends Statement implements Runnable {
|
|||
System.out.println("Timeout is "+timeout);
|
||||
thread.join(timeout);
|
||||
|
||||
if(throwable != null) {
|
||||
if (throwable != null) {
|
||||
throw throwable;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import org.slf4j.helpers.SubstituteLogger;
|
|||
abstract public class MultithreadedInitializationTest {
|
||||
final protected static int THREAD_COUNT = 4 + Runtime.getRuntime().availableProcessors() * 2;
|
||||
|
||||
private final List<Logger> createdLoggers = Collections.synchronizedList(new ArrayList<Logger>());
|
||||
private final List<Logger> createdLoggers = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
final protected AtomicLong eventCount = new AtomicLong(0);
|
||||
final private CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT + 1);
|
||||
|
|
|
|||
|
|
@ -114,13 +114,10 @@ public class AgentPremain {
|
|||
|
||||
System.err.println("Start at " + new Date());
|
||||
|
||||
Thread hook = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
long timePassed = System.currentTimeMillis() - start;
|
||||
System.err.println("Stop at " + new Date() + ", execution time = " + timePassed + " ms");
|
||||
}
|
||||
};
|
||||
Thread hook = new Thread(() -> {
|
||||
long timePassed = System.currentTimeMillis() - start;
|
||||
System.err.println("Stop at " + new Date() + ", execution time = " + timePassed + " ms");
|
||||
});
|
||||
Runtime.getRuntime().addShutdownHook(hook);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,8 +187,8 @@ public class LogTransformer implements ClassFileTransformer {
|
|||
private byte[] transform0(String className, Class<?> clazz, ProtectionDomain domain, byte[] bytes) {
|
||||
|
||||
try {
|
||||
for (int i = 0; i < ignore.length; i++) {
|
||||
if (className.startsWith(ignore[i])) {
|
||||
for (String s : ignore) {
|
||||
if (className.startsWith(s)) {
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
|
@ -263,9 +263,9 @@ public class LogTransformer implements ClassFileTransformer {
|
|||
// instrumented too.
|
||||
|
||||
CtBehavior[] methods = cl.getDeclaredBehaviors();
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
if (methods[i].isEmpty() == false) {
|
||||
doMethod(methods[i]);
|
||||
for (CtBehavior method : methods) {
|
||||
if (method.isEmpty() == false) {
|
||||
doMethod(method);
|
||||
}
|
||||
}
|
||||
b = cl.toBytecode();
|
||||
|
|
|
|||
|
|
@ -53,10 +53,10 @@ public class ToStringHelper {
|
|||
* is needed, but unfortunately the runtime library does not contain a
|
||||
* WeakHashSet class, so the behavior is emulated with a WeakHashmap with
|
||||
* the class as the key, and a Long containing the value of
|
||||
* System.currentTimeMilis when an instance of the class failed to render.
|
||||
* System.currentTimeMillis when an instance of the class failed to render.
|
||||
*/
|
||||
|
||||
final static Map<Class<?>, Object> unrenderableClasses = new WeakHashMap<Class<?>, Object>();
|
||||
final static Map<Class<?>, Object> unrenderableClasses = new WeakHashMap<>();
|
||||
|
||||
/**
|
||||
* Returns o.toString() unless it throws an exception (which causes it to be
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class Profiler implements TimeInstrument {
|
|||
final String name;
|
||||
final StopWatch globalStopWatch;
|
||||
|
||||
List<TimeInstrument> childTimeInstrumentList = new ArrayList<TimeInstrument>();
|
||||
List<TimeInstrument> childTimeInstrumentList = new ArrayList<>();
|
||||
|
||||
// optional field
|
||||
ProfilerRegistry profilerRegistry;
|
||||
|
|
@ -209,7 +209,7 @@ public class Profiler implements TimeInstrument {
|
|||
* @since 1.5.9
|
||||
*/
|
||||
public List<TimeInstrument> getCopyOfChildTimeInstruments() {
|
||||
List<TimeInstrument> copy = new ArrayList<TimeInstrument>(childTimeInstrumentList);
|
||||
List<TimeInstrument> copy = new ArrayList<>(childTimeInstrumentList);
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ import java.util.Map;
|
|||
*/
|
||||
public class ProfilerRegistry {
|
||||
|
||||
private static final InheritableThreadLocal<ProfilerRegistry> inheritableThreadLocal = new InheritableThreadLocal<ProfilerRegistry>();
|
||||
private static final InheritableThreadLocal<ProfilerRegistry> inheritableThreadLocal = new InheritableThreadLocal<>();
|
||||
|
||||
Map<String, Profiler> profilerMap = new HashMap<String, Profiler>();
|
||||
Map<String, Profiler> profilerMap = new HashMap<>();
|
||||
|
||||
public void put(Profiler profiler) {
|
||||
put(profiler.getName(), profiler);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import org.apache.log4j.spi.LoggingEvent;
|
|||
|
||||
public class ListAppender extends AppenderSkeleton {
|
||||
|
||||
public List<LoggingEvent> list = new ArrayList<LoggingEvent>();
|
||||
public final List<LoggingEvent> list = new ArrayList<>();
|
||||
|
||||
public boolean extractLocationInfo = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -79,9 +79,9 @@ public class XLoggerTest {
|
|||
logger.entry("a", "b", "c", "d", "e", "f");
|
||||
|
||||
assertEquals(6, listAppender.list.size());
|
||||
verify((LoggingEvent) listAppender.list.get(0), "entry");
|
||||
verify((LoggingEvent) listAppender.list.get(1), "entry with (1)");
|
||||
verify((LoggingEvent) listAppender.list.get(2), "entry with (test)");
|
||||
verify(listAppender.list.get(0), "entry");
|
||||
verify(listAppender.list.get(1), "entry with (1)");
|
||||
verify(listAppender.list.get(2), "entry with (test)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -92,9 +92,9 @@ public class XLoggerTest {
|
|||
assertEquals(Boolean.FALSE, logger.exit(false));
|
||||
|
||||
assertEquals(3, listAppender.list.size());
|
||||
verify((LoggingEvent) listAppender.list.get(0), "exit");
|
||||
verify((LoggingEvent) listAppender.list.get(1), "exit with (0)");
|
||||
verify((LoggingEvent) listAppender.list.get(2), "exit with (false)");
|
||||
verify(listAppender.list.get(0), "exit");
|
||||
verify(listAppender.list.get(1), "exit with (0)");
|
||||
verify(listAppender.list.get(2), "exit with (false)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -104,8 +104,8 @@ public class XLoggerTest {
|
|||
assertEquals(t, logger.throwing(t));
|
||||
assertEquals(t, logger.throwing(XLogger.Level.DEBUG, t));
|
||||
assertEquals(2, listAppender.list.size());
|
||||
verifyWithException((LoggingEvent) listAppender.list.get(0), "throwing", t);
|
||||
LoggingEvent event = (LoggingEvent) listAppender.list.get(1);
|
||||
verifyWithException(listAppender.list.get(0), "throwing", t);
|
||||
LoggingEvent event = listAppender.list.get(1);
|
||||
verifyWithLevelAndException(event, XLogger.Level.DEBUG, "throwing", t);
|
||||
}
|
||||
|
||||
|
|
@ -122,8 +122,8 @@ public class XLoggerTest {
|
|||
logger.catching(ex);
|
||||
logger.catching(XLogger.Level.DEBUG, ex);
|
||||
}
|
||||
verifyWithException((LoggingEvent) listAppender.list.get(0), "catching", t);
|
||||
verifyWithLevelAndException((LoggingEvent) listAppender.list.get(1), XLogger.Level.DEBUG, "catching", t);
|
||||
verifyWithException(listAppender.list.get(0), "catching", t);
|
||||
verifyWithLevelAndException(listAppender.list.get(1), XLogger.Level.DEBUG, "catching", t);
|
||||
}
|
||||
|
||||
// See http://jira.qos.ch/browse/SLF4J-105
|
||||
|
|
@ -156,10 +156,10 @@ public class XLoggerTest {
|
|||
public void testNoDoubleSubstitution_Bug421() {
|
||||
XLogger logger = XLoggerFactory.getXLogger("UnitTest");
|
||||
logger.error("{},{}", "foo", "[{}]");
|
||||
verify((LoggingEvent) listAppender.list.get(0), "foo,[{}]");
|
||||
verify(listAppender.list.get(0), "foo,[{}]");
|
||||
|
||||
logger.error("{},{}", "[{}]", "foo");
|
||||
verify((LoggingEvent) listAppender.list.get(1), "[{}],foo");
|
||||
verify(listAppender.list.get(1), "[{}],foo");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class SortAndPruneComposites {
|
|||
}
|
||||
|
||||
int[] pruneComposites(int[] sortedArray) {
|
||||
ArrayList<Integer> primesArray = new ArrayList<Integer>();
|
||||
ArrayList<Integer> primesArray = new ArrayList<>();
|
||||
for (int i = 0; i < originalArrrayLength; i++) {
|
||||
int n = sortedArray[i];
|
||||
if (isPrime(n)) {
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ class SLF4JPlarformLogger implements System.Logger {
|
|||
// The JDK uses a different formatting convention. We must invoke it now.
|
||||
message = String.format(message, params);
|
||||
}
|
||||
if(leb instanceof CallerBoundaryAware) {
|
||||
if (leb instanceof CallerBoundaryAware) {
|
||||
CallerBoundaryAware cba = (CallerBoundaryAware) leb;
|
||||
cba.setCallerBoundary(PRESUMED_CALLER_BOUNDARY);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class StringPrintStream extends PrintStream {
|
|||
PrintStream other;
|
||||
boolean duplicate = false;
|
||||
|
||||
public List<String> stringList = Collections.synchronizedList(new ArrayList<String>());
|
||||
public List<String> stringList = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
public StringPrintStream(PrintStream ps, boolean duplicate) {
|
||||
super(ps);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class JDK14LoggerFactory implements ILoggerFactory {
|
|||
ConcurrentMap<String, Logger> loggerMap;
|
||||
|
||||
public JDK14LoggerFactory() {
|
||||
loggerMap = new ConcurrentHashMap<String, Logger>();
|
||||
loggerMap = new ConcurrentHashMap<>();
|
||||
// ensure jul initialization. see SLF4J-359
|
||||
// note that call to java.util.logging.LogManager.getLogManager() fails on the Google App Engine platform. See
|
||||
// SLF4J-363
|
||||
|
|
|
|||
|
|
@ -77,8 +77,8 @@ public class JDK14AdapterLoggerNameTest {
|
|||
private void removeHandlers(Logger logger) {
|
||||
logger.setUseParentHandlers(false);
|
||||
Handler[] handlers = logger.getHandlers();
|
||||
for (int i = 0; i < handlers.length; i++) {
|
||||
logger.removeHandler(handlers[i]);
|
||||
for (Handler handler : handlers) {
|
||||
logger.removeHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ public class JDK14AdapterLoggerNameTest {
|
|||
assertNotNull("missing logger name", mockHandler.record.getLoggerName());
|
||||
}
|
||||
|
||||
private class MockHandler extends java.util.logging.Handler {
|
||||
private static class MockHandler extends java.util.logging.Handler {
|
||||
public LogRecord record;
|
||||
|
||||
public void close() throws SecurityException {
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ public class JDK14MultithreadedInitializationTest extends MultithreadedInitializ
|
|||
|
||||
private void removeAllHandlers(java.util.logging.Logger logger) {
|
||||
Handler[] handlers = logger.getHandlers();
|
||||
for (int i = 0; i < handlers.length; i++) {
|
||||
logger.removeHandler(handlers[i]);
|
||||
for (Handler handler : handlers) {
|
||||
logger.removeHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import java.util.logging.LogRecord;
|
|||
|
||||
public class ListHandler extends java.util.logging.Handler {
|
||||
|
||||
public List<LogRecord> recordList = new ArrayList<LogRecord>();
|
||||
public List<LogRecord> recordList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public class Log4jLoggerFactory implements ILoggerFactory {
|
|||
ConcurrentMap<String, Logger> loggerMap;
|
||||
|
||||
public Log4jLoggerFactory() {
|
||||
loggerMap = new ConcurrentHashMap<String, Logger>();
|
||||
loggerMap = new ConcurrentHashMap<>();
|
||||
// force log4j to initialize
|
||||
org.apache.log4j.LogManager.getRootLogger();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,8 +90,8 @@ public class Log4jMDCAdapter implements MDCAdapter {
|
|||
Map old = org.apache.log4j.MDC.getContext();
|
||||
|
||||
// we must cater for the case where the contextMap argument is null
|
||||
if(contextMap == null) {
|
||||
if(old != null) {
|
||||
if (contextMap == null) {
|
||||
if (old != null) {
|
||||
old.clear();
|
||||
}
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ public class InvocationTest {
|
|||
|
||||
@Test
|
||||
public void testMDCContextMapValues() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("ka", "va");
|
||||
map.put("kb", "vb");
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import org.apache.log4j.spi.LoggingEvent;
|
|||
|
||||
public class ListAppender extends AppenderSkeleton {
|
||||
|
||||
public List<LoggingEvent> list = new ArrayList<LoggingEvent>();
|
||||
public List<LoggingEvent> list = new ArrayList<>();
|
||||
|
||||
public boolean extractLocationInfo = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class RecursiveAppender extends AppenderSkeleton {
|
|||
int activationDelay = 0;
|
||||
String loggerName = "org.slf4j.impl.RecursiveAppender" + diff;
|
||||
|
||||
public List<LoggingEvent> events = new ArrayList<LoggingEvent>();
|
||||
public List<LoggingEvent> events = new ArrayList<>();
|
||||
|
||||
public RecursiveAppender() {
|
||||
System.out.println("XXXXXXX entering RecursiveAppender constructor");
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import org.slf4j.migrator.internal.ProgressListener;
|
|||
|
||||
public class FileSelector {
|
||||
|
||||
private List<File> javaFileList = new ArrayList<File>();
|
||||
private final List<File> javaFileList = new ArrayList<>();
|
||||
|
||||
ProgressListener pl;
|
||||
|
||||
|
|
@ -54,8 +54,8 @@ public class FileSelector {
|
|||
pl.onDirectory(file);
|
||||
File[] files = file.listFiles();
|
||||
if (files != null) {
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
selectFiles(files[i]);
|
||||
for (File value : files) {
|
||||
selectFiles(value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -102,8 +102,8 @@ public class InplaceFileConverter {
|
|||
}
|
||||
|
||||
private void writeReplacement(OutputStream os, String[] replacement) throws IOException {
|
||||
for (int i = 0; i < replacement.length; i++) {
|
||||
os.write(replacement[i].getBytes());
|
||||
for (String s : replacement) {
|
||||
os.write(s.getBytes());
|
||||
os.write(lineTerminator.getBytes());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,12 +38,10 @@ public class Main {
|
|||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Starting SLF4J Migrator");
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
MigratorFrame inst = new MigratorFrame();
|
||||
inst.setLocationRelativeTo(null);
|
||||
inst.setVisible(true);
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
MigratorFrame inst = new MigratorFrame();
|
||||
inst.setLocationRelativeTo(null);
|
||||
inst.setVisible(true);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ package org.slf4j.migrator;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
|
@ -38,18 +37,16 @@ import org.slf4j.migrator.line.RuleSet;
|
|||
|
||||
public class ProjectConverter {
|
||||
|
||||
private RuleSet ruleSet;
|
||||
private final RuleSet ruleSet;
|
||||
private List<ConversionException> exception;
|
||||
|
||||
ProgressListener progressListener;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
MigratorFrame inst = new MigratorFrame();
|
||||
inst.setLocationRelativeTo(null);
|
||||
inst.setVisible(true);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
MigratorFrame inst = new MigratorFrame();
|
||||
inst.setLocationRelativeTo(null);
|
||||
inst.setVisible(true);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -83,9 +80,7 @@ public class ProjectConverter {
|
|||
*/
|
||||
private void scanFileList(List<File> lstFiles) {
|
||||
progressListener.onFileScanBegin();
|
||||
Iterator<File> itFile = lstFiles.iterator();
|
||||
while (itFile.hasNext()) {
|
||||
File currentFile = itFile.next();
|
||||
for (File currentFile : lstFiles) {
|
||||
progressListener.onFileScan(currentFile);
|
||||
scanFile(currentFile);
|
||||
}
|
||||
|
|
@ -108,16 +103,14 @@ public class ProjectConverter {
|
|||
|
||||
public void addException(ConversionException exc) {
|
||||
if (exception == null) {
|
||||
exception = new ArrayList<ConversionException>();
|
||||
exception = new ArrayList<>();
|
||||
}
|
||||
exception.add(exc);
|
||||
}
|
||||
|
||||
public void printException() {
|
||||
if (exception != null) {
|
||||
Iterator<ConversionException> iterator = exception.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ConversionException exc = (ConversionException) iterator.next();
|
||||
for (ConversionException exc : exception) {
|
||||
exc.print();
|
||||
}
|
||||
exception = null;
|
||||
|
|
|
|||
|
|
@ -313,7 +313,7 @@ public class MigratorFrame extends JFrame implements ActionListener {
|
|||
|
||||
List<String> doSanityAnalysis() {
|
||||
|
||||
List<String> errorList = new ArrayList<String>();
|
||||
List<String> errorList = new ArrayList<>();
|
||||
if (!radioJCL.isSelected() && !radioLog4j.isSelected() && !radioJUL.isSelected()) {
|
||||
errorList.add("Please select the migration type: JCL, log4j, or JUL to SLF4J.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import java.util.List;
|
|||
|
||||
public class EmptyRuleSet implements RuleSet {
|
||||
|
||||
List<ConversionRule> list = new ArrayList<ConversionRule>();
|
||||
List<ConversionRule> list = new ArrayList<>();
|
||||
|
||||
public Iterator<ConversionRule> iterator() {
|
||||
return list.iterator();
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class JCLRuleSet implements RuleSet {
|
|||
|
||||
SingleConversionRule cr5 = new SingleConversionRule(Pattern.compile("LogFactory.getLog\\("), "LoggerFactory.getLogger(");
|
||||
|
||||
conversionRuleList = new ArrayList<ConversionRule>();
|
||||
conversionRuleList = new ArrayList<>();
|
||||
conversionRuleList.add(cr0);
|
||||
conversionRuleList.add(cr1);
|
||||
conversionRuleList.add(cr2);
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class JULRuleSet implements RuleSet {
|
|||
SingleConversionRule crWarning = new SingleConversionRule(Pattern.compile("\\.warning\\("), ".warn(");
|
||||
SingleConversionRule crSevere = new SingleConversionRule(Pattern.compile("\\.severe\\("), ".error(");
|
||||
|
||||
conversionRuleList = new ArrayList<ConversionRule>();
|
||||
conversionRuleList = new ArrayList<>();
|
||||
conversionRuleList.add(crImport0);
|
||||
conversionRuleList.add(crImport1);
|
||||
conversionRuleList.add(crImport2);
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class Log4jRuleSet implements RuleSet {
|
|||
|
||||
SingleConversionRule variable1 = new SingleConversionRule(Pattern.compile("(^Category\\b)"), "Logger");
|
||||
|
||||
conversionRuleList = new ArrayList<ConversionRule>();
|
||||
conversionRuleList = new ArrayList<>();
|
||||
conversionRuleList.add(crImport0);
|
||||
conversionRuleList.add(catImport);
|
||||
conversionRuleList.add(crImport1);
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class TrivialMatcher implements RuleSet {
|
|||
cr1.addReplacement(3, "");
|
||||
// no replacement for the third group it will remains the same
|
||||
|
||||
conversionRuleList = new ArrayList<ConversionRule>();
|
||||
conversionRuleList = new ArrayList<>();
|
||||
conversionRuleList.add(cr);
|
||||
conversionRuleList.add(cr1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ public class MultithreadedInitializationTest {
|
|||
|
||||
public static final String LINE_SEP = System.getProperty("line.separator");
|
||||
PrintStream other;
|
||||
List<String> stringList = new ArrayList<String>();
|
||||
List<String> stringList = new ArrayList<>();
|
||||
|
||||
public StringPrintStream(PrintStream ps) {
|
||||
super(ps);
|
||||
|
|
|
|||
|
|
@ -359,7 +359,7 @@ public class SimpleLogger extends LegacyAbstractLogger {
|
|||
List<Marker> markers = null;
|
||||
|
||||
if (marker != null) {
|
||||
markers = new ArrayList<Marker>();
|
||||
markers = new ArrayList<>();
|
||||
markers.add(marker);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,14 +97,12 @@ public class SimpleLoggerConfiguration {
|
|||
|
||||
private void loadProperties() {
|
||||
// Add props from the resource simplelogger.properties
|
||||
InputStream in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
|
||||
public InputStream run() {
|
||||
ClassLoader threadCL = Thread.currentThread().getContextClassLoader();
|
||||
if (threadCL != null) {
|
||||
return threadCL.getResourceAsStream(CONFIGURATION_FILE);
|
||||
} else {
|
||||
return ClassLoader.getSystemResourceAsStream(CONFIGURATION_FILE);
|
||||
}
|
||||
InputStream in = AccessController.doPrivileged((PrivilegedAction<InputStream>) () -> {
|
||||
ClassLoader threadCL = Thread.currentThread().getContextClassLoader();
|
||||
if (threadCL != null) {
|
||||
return threadCL.getResourceAsStream(CONFIGURATION_FILE);
|
||||
} else {
|
||||
return ClassLoader.getSystemResourceAsStream(CONFIGURATION_FILE);
|
||||
}
|
||||
});
|
||||
if (null != in) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class SimpleLoggerFactory implements ILoggerFactory {
|
|||
ConcurrentMap<String, Logger> loggerMap;
|
||||
|
||||
public SimpleLoggerFactory() {
|
||||
loggerMap = new ConcurrentHashMap<String, Logger>();
|
||||
loggerMap = new ConcurrentHashMap<>();
|
||||
SimpleLogger.lazyInit();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -445,7 +445,7 @@ dt:hover .anchor {
|
|||
padding-top: 3px;
|
||||
padding-right: 16px;
|
||||
float: left;
|
||||
height: 18px;div
|
||||
height: 18px;
|
||||
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
|
||||
white-space: nowrap;
|
||||
background-color: white;
|
||||
|
|
|
|||
Loading…
Reference in New Issue