KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bak > pcj > benchmark > ResultComparator


1 /*
2  * Primitive Collections for Java.
3  * Copyright (C) 2003 Søren Bak
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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 JavaDoc {
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 &lt; o2</tt>; returns
36      * <tt>0</tt> if <tt>o1 == o2</tt>; returns
37      * <tt>1</tt> if <tt>o1 &gt; 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 JavaDoc o1, Object JavaDoc o2) {
48         Result r1 = (Result)o1;
49         Result r2 = (Result)o2;
50
51         int cBenchmarkId = r1.getBenchmarkId().compareTo(r2.getBenchmarkId());
52         if (cBenchmarkId < 0)
53             return -1;
54         if (cBenchmarkId > 0)
55             return 1;
56
57         int cClassId = r1.getClassId().compareTo(r2.getClassId());
58         if (cClassId < 0)
59             return -1;
60         if (cClassId > 0)
61             return 1;
62         
63         int cTaskId = r1.getTaskId().compareTo(r2.getTaskId());
64         if (cTaskId < 0)
65             return -1;
66         if (cTaskId > 0)
67             return 1;
68
69         int cDataSetId = r1.getDataSetId().compareTo(r2.getDataSetId());
70         if (cDataSetId < 0)
71             return -1;
72         if (cDataSetId > 0)
73             return 1;
74         return 0;
75
76     }
77
78 }
Popular Tags