Update of /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/nodes
In directory usw-pr-cvs1:/tmp/cvs-serv3041
Added Files:
PDataComparator.java
Log Message:
comparator of PDataNode
--- NEW FILE: PDataComparator.java ---
/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"); you may not use this file except
* in compliance with the License. A copy of the License is available
* at http://www.sun.com/
*
* The Original Code is the Java Profiler module. The Initial Developers
* of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
* Lukas Petru and Marek Przeczek.
*
* Portions created by Jan Stola are Copyright (C) 2000-2001.
* All Rights Reserved.
*
* Portions created by Pavel Vacha are Copyright (C) 2000-2001.
* All Rights Reserved.
*
* Portions created by Michal Pise are Copyright (C) 2000-2001.
* All Rights Reserved.
*
* Portions created by Petr Luner are Copyright (C) 2000-2001.
* All Rights Reserved.
*
* Portions created by Lukas Petru are Copyright (C) 2000-2001.
* All Rights Reserved.
*
* Portions created by Marek Przeczek are Copyright (C) 2000-2001.
* All Rights Reserved.
*
* Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
* Lukas Petru and Marek Przeczek.
*/
package net.sourceforge.javaprofiler.module.nodes;
import java.util.*;
import net.sourceforge.javaprofiler.jpi.AllocStat;
import net.sourceforge.javaprofiler.jpi.CPUStat;
import net.sourceforge.javaprofiler.jpi.MonStat;
/** This class provides five different comparators of <code>PDataNode</code>
* objects. The first is zero comparator which treats all objects equal, the
* next comparator types order by: Name, Alloc, CPU and Mon.
* @author Lukas Petru
*/
class PDataComparator implements Comparator {
/** Compare all objects as equal. */
public static final int ZERO=0;
/** Compare objects by name. */
public static final int NAME=1;
/** Compare objects by Alloc. */
public static final int ALLOC=2;
/** Compare objects by CPU. */
public static final int CPU=3;
/** Compare objects by Mon. */
public static final int MON=4;
private int type;
/** Constructs a comparator of selected type. Use constants defined in this
* class.
*/
PDataComparator(int compType) {
type=compType;
}
public int compare(Object o1, Object o2) {
if (type==ZERO)
return 0;
if ((o1 instanceof PDataNode) && (o2 instanceof PDataNode)) {
switch(type) {
case NAME:
return nameCompare((PDataNode) o1, (PDataNode) o2);
case ALLOC:
return allocCompare((PDataNode) o1, (PDataNode) o2);
case CPU:
return cpuCompare((PDataNode) o1, (PDataNode) o2);
case MON:
return monCompare((PDataNode) o1, (PDataNode) o2);
}
throw new IllegalArgumentException("Comparator type");
} else
throw new IllegalArgumentException("types:"+o1.getClass()+","+
o2.getClass());
}
private int nameCompare(PDataNode n1, PDataNode n2) {
return n1.getDisplayName().compareTo(n2.getDisplayName());
}
/** Compares by Alloc in descending order. */
private int allocCompare(PDataNode n1, PDataNode n2) {
AllocStat a1=(AllocStat) n1.getDataObject();
AllocStat a2=(AllocStat) n2.getDataObject();
long d=a1.getLiveInstancesSize() - a2.getLiveInstancesSize();
if (d!=0)
return (-d>0) ? 1 : -1;
d=a1.getTotalInstancesSize() - a2.getTotalInstancesSize();
if (d!=0)
return (-d>0) ? 1 : -1;
else
return 0;
}
/** Compares by CPU in descending order. */
private int cpuCompare(PDataNode n1, PDataNode n2) {
CPUStat a1=(CPUStat) n1.getDataObject();
CPUStat a2=(CPUStat) n2.getDataObject();
long d=a1.getCPUPureTime() - a2.getCPUPureTime();
if (d!=0)
return (-d>0) ? 1 : -1;
d=a1.getCPUHitsCount() - a2.getCPUHitsCount();
if (d!=0)
return (-d>0) ? 1 : -1;
else
return 0;
}
/** Compares by Mon in descending order. */
private int monCompare(PDataNode n1, PDataNode n2) {
MonStat a1=(MonStat) n1.getDataObject();
MonStat a2=(MonStat) n2.getDataObject();
long d=a1.getMonPureTime() - a2.getMonPureTime();
if (d!=0)
return (-d>0) ? 1 : -1;
d=a1.getMonHitsCount() - a2.getMonHitsCount();
if (d!=0)
return (-d>0) ? 1 : -1;
else
return 0;
}
}
/*
* $Log: PDataComparator.java,v $
* Revision 1.1 2002/08/31 08:42:20 petrul
* comparator of PDataNode
*
*/
|