01: /*
02: * Primitive Collections for Java.
03: * Copyright (C) 2003 Søren Bak
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19: package bak.pcj.benchmark;
20:
21: /**
22: * This class represents comparators of results from benchmarks.
23: *
24: * @author Søren Bak
25: * @version 1.0 2003/4/1
26: * @since 1.0
27: */
28: class ResultComparator implements java.util.Comparator {
29:
30: /**
31: * Compares two {@link Result Result} objects for order. Results
32: * are ordered by benchmark id, class id, task id, and
33: * then data set id.
34: *
35: * @return <tt>-1</tt> if <tt>o1 < o2</tt>; returns
36: * <tt>0</tt> if <tt>o1 == o2</tt>; returns
37: * <tt>1</tt> if <tt>o1 > o2</tt>;
38: *
39: * @throws NullPointerException
40: * if <tt>o1</tt> is <tt>null</tt>;
41: * if <tt>o2</tt> is <tt>null</tt>.
42: *
43: * @throws ClassCastException
44: * if <tt>o1</tt> is not of class {@link Result Result};
45: * if <tt>o2</tt> is not of class {@link Result Result}.
46: */
47: public int compare(Object o1, Object o2) {
48: Result r1 = (Result) o1;
49: Result r2 = (Result) o2;
50:
51: int cBenchmarkId = r1.getBenchmarkId().compareTo(
52: r2.getBenchmarkId());
53: if (cBenchmarkId < 0)
54: return -1;
55: if (cBenchmarkId > 0)
56: return 1;
57:
58: int cClassId = r1.getClassId().compareTo(r2.getClassId());
59: if (cClassId < 0)
60: return -1;
61: if (cClassId > 0)
62: return 1;
63:
64: int cTaskId = r1.getTaskId().compareTo(r2.getTaskId());
65: if (cTaskId < 0)
66: return -1;
67: if (cTaskId > 0)
68: return 1;
69:
70: int cDataSetId = r1.getDataSetId().compareTo(r2.getDataSetId());
71: if (cDataSetId < 0)
72: return -1;
73: if (cDataSetId > 0)
74: return 1;
75: return 0;
76:
77: }
78:
79: }
|