本文整理汇总了Java中com.sun.tools.hat.internal.util.Comparer类的典型用法代码示例。如果您正苦于以下问题:Java Comparer类的具体用法?Java Comparer怎么用?Java Comparer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Comparer类属于com.sun.tools.hat.internal.util包,在下文中一共展示了Comparer类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printFullObject
import com.sun.tools.hat.internal.util.Comparer; //导入依赖的package包/类
private void printFullObject(JavaObject obj) {
out.print("<h1>instance of ");
print(obj.toString());
out.print(" <small>(" + obj.getSize() + " bytes)</small>");
out.println("</h1>\n");
out.println("<h2>Class:</h2>");
printClass(obj.getClazz());
out.println("<h2>Instance data members:</h2>");
final JavaThing[] things = obj.getFields();
final JavaField[] fields = obj.getClazz().getFieldsForInstance();
Integer[] hack = new Integer[things.length];
for (int i = 0; i < things.length; i++) {
hack[i] = new Integer(i);
}
ArraySorter.sort(hack, new Comparer() {
public int compare(Object lhs, Object rhs) {
JavaField left = fields[((Integer) lhs).intValue()];
JavaField right = fields[((Integer) rhs).intValue()];
return left.getName().compareTo(right.getName());
}
});
for (int i = 0; i < things.length; i++) {
int index = hack[i].intValue();
printField(fields[index]);
out.print(" : ");
printThing(things[index]);
out.println("<br>");
}
}
示例2: ReachableObjects
import com.sun.tools.hat.internal.util.Comparer; //导入依赖的package包/类
public ReachableObjects(JavaHeapObject root,
final ReachableExcludes excludes) {
this.root = root;
final Hashtable<JavaHeapObject, JavaHeapObject> bag = new Hashtable<JavaHeapObject, JavaHeapObject>();
final Hashtable<String, String> fieldsExcluded = new Hashtable<String, String>(); //Bag<String>
final Hashtable<String, String> fieldsUsed = new Hashtable<String, String>(); // Bag<String>
JavaHeapObjectVisitor visitor = new AbstractJavaHeapObjectVisitor() {
public void visit(JavaHeapObject t) {
// Size is zero for things like integer fields
if (t != null && t.getSize() > 0 && bag.get(t) == null) {
bag.put(t, t);
t.visitReferencedObjects(this);
}
}
public boolean mightExclude() {
return excludes != null;
}
public boolean exclude(JavaClass clazz, JavaField f) {
if (excludes == null) {
return false;
}
String nm = clazz.getName() + "." + f.getName();
if (excludes.isExcluded(nm)) {
fieldsExcluded.put(nm, nm);
return true;
} else {
fieldsUsed.put(nm, nm);
return false;
}
}
};
// Put the closure of root and all objects reachable from root into
// bag (depth first), but don't include root:
visitor.visit(root);
bag.remove(root);
// Now grab the elements into a vector, and sort it in decreasing size
JavaThing[] things = new JavaThing[bag.size()];
int i = 0;
for (Enumeration e = bag.elements(); e.hasMoreElements(); ) {
things[i++] = (JavaThing) e.nextElement();
}
ArraySorter.sort(things, new Comparer() {
public int compare(Object lhs, Object rhs) {
JavaThing left = (JavaThing) lhs;
JavaThing right = (JavaThing) rhs;
int diff = right.getSize() - left.getSize();
if (diff != 0) {
return diff;
}
return left.compareTo(right);
}
});
this.reachables = things;
this.totalSize = root.getSize();
for (i = 0; i < things.length; i++) {
this.totalSize += things[i].getSize();
}
excludedFields = getElements(fieldsExcluded);
usedFields = getElements(fieldsUsed);
}
示例3: run
import com.sun.tools.hat.internal.util.Comparer; //导入依赖的package包/类
public void run() {
startHtml("All Members of the Rootset");
Root[] roots = snapshot.getRootsArray();
ArraySorter.sort(roots, new Comparer() {
public int compare(Object lhs, Object rhs) {
Root left = (Root) lhs;
Root right = (Root) rhs;
int d = left.getType() - right.getType();
if (d != 0) {
return -d; // More interesting values are *higher*
}
return left.getDescription().compareTo(right.getDescription());
}
});
int lastType = Root.INVALID_TYPE;
for (int i= 0; i < roots.length; i++) {
Root root = roots[i];
if (root.getType() != lastType) {
lastType = root.getType();
out.print("<h2>");
print(root.getTypeName() + " References");
out.println("</h2>");
}
printRoot(root);
if (root.getReferer() != null) {
out.print("<small> (from ");
printThingAnchorTag(root.getReferer().getId());
print(root.getReferer().toString());
out.print(")</a></small>");
}
out.print(" :<br>");
JavaThing t = snapshot.findThing(root.getId());
if (t != null) { // It should always be
print("--> ");
printThing(t);
out.println("<br>");
}
}
out.println("<h2>Other Queries</h2>");
out.println("<ul>");
out.println("<li>");
printAnchorStart();
out.print("\">");
print("Show All Classes");
out.println("</a>");
out.println("</ul>");
endHtml();
}