Removed cyclic dependencies
This commit is contained in:
parent
027b8b7f73
commit
c043e2bf1c
@ -28,9 +28,6 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jboss.netty.logging.InternalLogger;
|
|
||||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of utility methods related with a {@link Map}.
|
* A set of utility methods related with a {@link Map}.
|
||||||
*
|
*
|
||||||
@ -40,8 +37,6 @@ import org.jboss.netty.logging.InternalLoggerFactory;
|
|||||||
* @version $Rev$, $Date$
|
* @version $Rev$, $Date$
|
||||||
*/
|
*/
|
||||||
public class MapUtil {
|
public class MapUtil {
|
||||||
private static final InternalLogger logger =
|
|
||||||
InternalLoggerFactory.getInstance(MapUtil.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns {@code true} if and only if the specified {@code map} is an
|
* Returns {@code true} if and only if the specified {@code map} is an
|
||||||
@ -51,81 +46,53 @@ public class MapUtil {
|
|||||||
public static boolean isOrderedMap(Map<?, ?> map) {
|
public static boolean isOrderedMap(Map<?, ?> map) {
|
||||||
Class<?> mapType = map.getClass();
|
Class<?> mapType = map.getClass();
|
||||||
if (LinkedHashMap.class.isAssignableFrom(mapType)) {
|
if (LinkedHashMap.class.isAssignableFrom(mapType)) {
|
||||||
if (logger.isDebugEnabled()) {
|
// LinkedHashMap is an ordered map.
|
||||||
logger.debug(mapType.getSimpleName() + " is an ordered map.");
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
// Not a LinkedHashMap - start autodetection.
|
||||||
logger.debug(
|
|
||||||
mapType.getName() + " is not a " +
|
|
||||||
LinkedHashMap.class.getSimpleName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detect Apache Commons Collections OrderedMap implementations.
|
// Detect Apache Commons Collections OrderedMap implementations.
|
||||||
Class<?> type = mapType;
|
Class<?> type = mapType;
|
||||||
while (type != null) {
|
while (type != null) {
|
||||||
for (Class<?> i: type.getInterfaces()) {
|
for (Class<?> i: type.getInterfaces()) {
|
||||||
if (i.getName().endsWith("OrderedMap")) {
|
if (i.getName().endsWith("OrderedMap")) {
|
||||||
if (logger.isDebugEnabled()) {
|
// Seems like it's an ordered map - guessed from that
|
||||||
logger.debug(
|
// it implements OrderedMap interface.
|
||||||
mapType.getSimpleName() +
|
|
||||||
" is an ordered map (guessed from that it " +
|
|
||||||
" implements OrderedMap interface.)");
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
type = type.getSuperclass();
|
type = type.getSuperclass();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
// Does not implement OrderedMap interface. As a last resort, try to
|
||||||
logger.debug(
|
// create a new instance and test if the insertion order is maintained.
|
||||||
mapType.getName() +
|
|
||||||
" does not implement OrderedMap interface.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Last resort: try to create a new instance and test if it maintains
|
|
||||||
// the insertion order.
|
|
||||||
logger.debug(
|
|
||||||
"Last resort; trying to create a new map instance with a " +
|
|
||||||
"default constructor and test if insertion order is " +
|
|
||||||
"maintained.");
|
|
||||||
|
|
||||||
Map newMap;
|
Map newMap;
|
||||||
try {
|
try {
|
||||||
newMap = (Map) mapType.newInstance();
|
newMap = (Map) mapType.newInstance();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (logger.isDebugEnabled()) {
|
// No default constructor - cannot proceed anymore.
|
||||||
logger.debug(
|
|
||||||
"Failed to create a new map instance of '" +
|
|
||||||
mapType.getName() +"'.", e);
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run some tests.
|
||||||
List<String> expectedKeys = new ArrayList<String>();
|
List<String> expectedKeys = new ArrayList<String>();
|
||||||
String dummyValue = "dummyValue";
|
String dummyValue = "dummyValue";
|
||||||
for (int i = 0; i < ORDER_TEST_SAMPLES.length; i ++) {
|
for (short element: ORDER_TEST_SAMPLES) {
|
||||||
String key = String.valueOf(ORDER_TEST_SAMPLES[i]);
|
String key = String.valueOf(element);
|
||||||
newMap.put(key, dummyValue);
|
newMap.put(key, dummyValue);
|
||||||
expectedKeys.add(key);
|
expectedKeys.add(key);
|
||||||
|
|
||||||
Iterator<String> it = expectedKeys.iterator();
|
Iterator<String> it = expectedKeys.iterator();
|
||||||
for (Object actualKey: newMap.keySet()) {
|
for (Object actualKey: newMap.keySet()) {
|
||||||
if (!it.next().equals(actualKey)) {
|
if (!it.next().equals(actualKey)) {
|
||||||
if (logger.isDebugEnabled()) {
|
// Did not pass the test.
|
||||||
logger.debug(
|
|
||||||
"The specified map didn't pass the insertion " +
|
|
||||||
"order test after " + (i + 1) + " tries.");
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("The specified map passed the insertion order test.");
|
// The specified map passed the insertion order test.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,8 +22,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.jboss.netty.util;
|
package org.jboss.netty.util;
|
||||||
|
|
||||||
import org.jboss.netty.logging.InternalLogger;
|
|
||||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Meta {@link Runnable} that changes the current thread name and reverts it
|
* Meta {@link Runnable} that changes the current thread name and reverts it
|
||||||
@ -36,8 +34,6 @@ import org.jboss.netty.logging.InternalLoggerFactory;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ThreadRenamingRunnable implements Runnable {
|
public class ThreadRenamingRunnable implements Runnable {
|
||||||
private static final InternalLogger logger =
|
|
||||||
InternalLoggerFactory.getInstance(ThreadRenamingRunnable.class);
|
|
||||||
|
|
||||||
private final Runnable runnable;
|
private final Runnable runnable;
|
||||||
private final String threadName;
|
private final String threadName;
|
||||||
@ -69,8 +65,6 @@ public class ThreadRenamingRunnable implements Runnable {
|
|||||||
renamed = true;
|
renamed = true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Probably SecurityException.
|
// Probably SecurityException.
|
||||||
logger.warn(
|
|
||||||
"Failed to set the current thread name.", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the actual runnable and revert the name back when it ends.
|
// Run the actual runnable and revert the name back when it ends.
|
||||||
|
Loading…
Reference in New Issue
Block a user