private static final long BUILD_UPDATE_TIMEOUT = 500;
private static final int[] DEFAULT_WEIGHT = { 1, 3 };
- private Comparator<ITimeGraphEntry> fComparator = new Comparator<ITimeGraphEntry>() {
- @Override
- public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) {
- if (!((o1 instanceof VirtualMachineViewEntry) && (o2 instanceof VirtualMachineViewEntry))) {
- return 0;
- }
- VirtualMachineViewEntry entry1 = (VirtualMachineViewEntry) o1;
- VirtualMachineViewEntry entry2 = (VirtualMachineViewEntry) o2;
- int cmp = entry1.getType().compareTo(entry2.getType());
- /* FIXME: Threads should be ordered by their thread IDs instead */
- if (cmp == 0) {
- cmp = entry1.getName().compareTo(entry2.getName());
- }
- return cmp;
- }
- };
+ private Comparator<ITimeGraphEntry> fComparator = VirtualMachineViewEntry.getComparator();
// ------------------------------------------------------------------------
// Constructors
@Override
public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) {
-
- int result = 0;
-
- if ((o1 instanceof VirtualMachineViewEntry) && (o2 instanceof VirtualMachineViewEntry)) {
- VirtualMachineViewEntry entry1 = (VirtualMachineViewEntry) o1;
- VirtualMachineViewEntry entry2 = (VirtualMachineViewEntry) o2;
- result = entry1.getType().compareTo(entry2.getType());
- if (result == 0) {
+ if (!((o1 instanceof VirtualMachineViewEntry) && (o2 instanceof VirtualMachineViewEntry))) {
+ return 0;
+ }
+ VirtualMachineViewEntry entry1 = (VirtualMachineViewEntry) o1;
+ VirtualMachineViewEntry entry2 = (VirtualMachineViewEntry) o2;
+ int result = entry1.getType().compareTo(entry2.getType());
+ if (result == 0) {
+ /* If there is a numeric ID, use it instead */
+ if (entry1.getNumericId() != -1) {
+ result = entry1.getNumericId().compareTo(entry2.getNumericId());
+ } else {
result = entry1.getId().compareTo(entry2.getId());
}
}
* @return A new {@link VirtualMachineViewEntry} object
*/
public VirtualMachineViewEntry build() {
- switch(fbType) {
+ switch (fbType) {
case VCPU:
fbEntryName = Messages.VmView_VCpu + ' ' + fbEntryName;
break;
/**
* Set the intervals for the threads of the corresponding virtual machine.
- * This should be called only if the type of this entry is {@link Type#VM}.
+ * This should be called only if the type of this entry is
+ * {@link Type#VM}.
*
* @param threadIntervals
* The map of intervals for each thread ID
fThreadIntervals = threadIntervals;
}
+ /**
+ * Get the default implementation of virtual machine entry comparator
+ *
+ * @return A virtual machine entry comparator
+ */
+ public static Comparator<ITimeGraphEntry> getComparator() {
+ return COMPARATOR;
+ }
}