Added countEntrySet() so that you can do:
for (CountHashMap.Entry entry : cmap.countEntrySet()) {
which you can't do with the somewhat butchered current entrySet()
implementation. Indeed, I'm not sure quite how one is supposed to use that.
Perhaps in an iterator and cast the result to a CountHashMap.Entry?
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2319 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
// $Id$
|
||||
//
|
||||
// samskivert library - useful routines for java programs
|
||||
// Copyright (C) 2001-2007 Michael Bayne
|
||||
//
|
||||
// Copyright (C) 2001-2008 Michael Bayne
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
@@ -134,6 +134,14 @@ public class CountHashMap<K> extends HashMap<K, int[]>
|
||||
return new CountEntrySet(super.entrySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of {@link Entry} records which can be used to easily obtain our count.
|
||||
*/
|
||||
public Set<Entry<K>> countEntrySet ()
|
||||
{
|
||||
return new CountEntrySet<K>(super.entrySet());
|
||||
}
|
||||
|
||||
protected static class CountEntryImpl<K>
|
||||
implements Entry<K>
|
||||
{
|
||||
@@ -156,7 +164,7 @@ public class CountHashMap<K> extends HashMap<K, int[]>
|
||||
{
|
||||
return _entry.getValue();
|
||||
}
|
||||
|
||||
|
||||
public int hashCode ()
|
||||
{
|
||||
return _entry.hashCode();
|
||||
@@ -226,7 +234,7 @@ public class CountHashMap<K> extends HashMap<K, int[]>
|
||||
{
|
||||
return CountHashMap.this.size();
|
||||
}
|
||||
|
||||
|
||||
public void clear ()
|
||||
{
|
||||
CountHashMap.this.clear();
|
||||
|
||||
@@ -53,6 +53,39 @@ public class JDK14Logger implements Logger.Factory
|
||||
return getLogger(clazz.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Infers the caller of a Logger method from the current stack trace. This can be used by
|
||||
* wrappers to provide the correct calling class and method information to their underlying log
|
||||
* implementation.
|
||||
*
|
||||
* @return a two element array containing { class name, method name } or { null, null } if the
|
||||
* caller could not be inferred.
|
||||
*/
|
||||
protected String[] inferCaller ()
|
||||
{
|
||||
String self = getClass().getName();
|
||||
|
||||
// locate ourselves in the call stack
|
||||
StackTraceElement[] stack = (new Throwable()).getStackTrace();
|
||||
int ii = 0;
|
||||
for (; ii < stack.length; ii++) {
|
||||
if (self.equals(stack[ii].getClassName())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.err.println("Found self at " + ii);
|
||||
// now locate the first thing that's not us, that's the caller
|
||||
for (; ii < stack.length; ii++) {
|
||||
String cname = stack[ii].getClassName();
|
||||
if (!cname.equals(self)) {
|
||||
System.err.println("Found non-self at " + ii + " " + cname);
|
||||
return new String[] { cname, stack[ii].getMethodName() };
|
||||
}
|
||||
}
|
||||
System.err.println("Failed to find non-self.");
|
||||
return new String[] { null, null };
|
||||
}
|
||||
|
||||
protected static class Impl extends Logger
|
||||
{
|
||||
public Impl (java.util.logging.Logger impl)
|
||||
|
||||
Reference in New Issue
Block a user