Automatic toString() for LockBasedStorageManager
This commit is contained in:
@@ -426,6 +426,13 @@ public class StorageManagerTest extends TestCase {
|
|||||||
assertEquals(2, c.getCount());
|
assertEquals(2, c.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// toString()
|
||||||
|
|
||||||
|
public void testToString() throws Exception {
|
||||||
|
assertTrue("Should mention the setUp() method of this class: " + m.toString(),
|
||||||
|
m.toString().contains(getClass().getSimpleName() + ".setUp("));
|
||||||
|
}
|
||||||
|
|
||||||
// Utilities
|
// Utilities
|
||||||
|
|
||||||
private static <K, V> Function0<V> apply(final Function1<K, V> f, final K x) {
|
private static <K, V> Function0<V> apply(final Function1<K, V> f, final K x) {
|
||||||
|
|||||||
@@ -31,27 +31,36 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||||||
|
|
||||||
public class LockBasedStorageManager implements StorageManager {
|
public class LockBasedStorageManager implements StorageManager {
|
||||||
|
|
||||||
public static final StorageManager NO_LOCKS = new LockBasedStorageManager(NoLock.INSTANCE) {
|
public static final StorageManager NO_LOCKS = new LockBasedStorageManager("NO_LOCKS", NoLock.INSTANCE) {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected <T> RecursionDetectedResult<T> recursionDetectedDefault() {
|
protected <T> RecursionDetectedResult<T> recursionDetectedDefault() {
|
||||||
return RecursionDetectedResult.fallThrough();
|
return RecursionDetectedResult.fallThrough();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "NO_LOCKS";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
protected final Lock lock;
|
protected final Lock lock;
|
||||||
|
private final String debugText;
|
||||||
|
|
||||||
public LockBasedStorageManager() {
|
public LockBasedStorageManager() {
|
||||||
this(new ReentrantLock());
|
this(getPointOfConstruction(), new ReentrantLock());
|
||||||
}
|
}
|
||||||
|
|
||||||
private LockBasedStorageManager(@NotNull Lock lock) {
|
private static String getPointOfConstruction() {
|
||||||
|
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
|
||||||
|
// we need to skip frames for getStackTrace(), this method and the constructor that's calling it
|
||||||
|
if (trace.length <= 3) return "<unknown creating class>";
|
||||||
|
return trace[3].toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private LockBasedStorageManager(@NotNull String debugText, @NotNull Lock lock) {
|
||||||
this.lock = lock;
|
this.lock = lock;
|
||||||
|
this.debugText = debugText;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode()) + " (" + debugText + ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user