01: package org.testng.internal;
02:
03: import java.util.Comparator;
04:
05: import org.testng.ITestNGMethod;
06:
07: public class MethodInstance {
08: private ITestNGMethod m_method;
09: private Object[] m_instances;
10:
11: public MethodInstance(ITestNGMethod method, Object[] instances) {
12: m_method = method;
13: m_instances = instances;
14: }
15:
16: public ITestNGMethod getMethod() {
17: return m_method;
18: }
19:
20: public Object[] getInstances() {
21: return m_instances;
22: }
23:
24: public String toString() {
25: return "[MethodInstance m:" + m_method + " i:" + m_instances[0];
26: }
27:
28: public static final Comparator<MethodInstance> SORT_BY_CLASS = new Comparator<MethodInstance>() {
29: public int compare(MethodInstance o1, MethodInstance o2) {
30: int result = o1.getMethod().getTestClass().getName()
31: .compareTo(o2.getMethod().getTestClass().getName());
32: if (result == 0) {
33: // if they have a single instance try to use it while performing the order
34: Object[] i1 = o1.getInstances();
35: Object[] i2 = o2.getInstances();
36: if (i1.length == 1 && i1.length == i2.length) {
37: int h1 = i1[0].hashCode();
38: int h2 = i2[0].hashCode();
39: if (h1 != h2) {
40: return h1 > h2 ? 1 : -1;
41: }
42: }
43: }
44:
45: return result;
46: }
47: };
48:
49: }
|