KickJava   Java API By Example, From Geeks To Geeks.

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


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 import bak.pcj.list.IntList;
22
23 /**
24  * This class represents data sets for benchmarks. A data set contains
25  * three lists of equal length. Each list has only distinct values
26  * and the lists are all disjoint.
27  *
28  * @author Søren Bak
29  * @version 1.0 2003/5/1
30  * @since 1.0
31  */

32 public abstract class DataSet {
33
34     private int[][] data;
35     private Integer JavaDoc[][] dataObjects;
36     private String JavaDoc id;
37     private int size;
38
39     /**
40      * Creates a new data set with a specified id and size.
41      *
42      * @param id
43      * the identifier of the new data set. Only used for
44      * formatting a report.
45      *
46      * @param size
47      * the size of the lists in the new data set.
48      *
49      * @throws NullPointerException
50      * if <tt>id</tt> is <tt>null</tt>.
51      *
52      * @throws IllegalArgumentException
53      * if <tt>size</tt> is not positive.
54      */

55     protected DataSet(String JavaDoc id, int size) {
56         if (id == null)
57             throw new NullPointerException JavaDoc();
58         if (size <= 0)
59             throw new IllegalArgumentException JavaDoc();
60         this.id = id;
61         this.size = size;
62         data = new int[3][];
63         dataObjects = new Integer JavaDoc[3][];
64     }
65
66     /**
67      * Returns a specified list of this data set.
68      *
69      * @param n
70      * the index of the list to return.
71      *
72      * @throws IndexOutOfBoundsException
73      * if <tt>n</tt> is negative or greater than <tt>2</tt>.
74      */

75     public int[] get(int n) {
76         if (data[n] == null)
77             data[n] = createList(n, size);
78         return data[n];
79     }
80
81     /**
82      * Returns a specified list of this data set as objects.
83      *
84      * @param n
85      * the index of the list to return.
86      *
87      * @throws IndexOutOfBoundsException
88      * if <tt>n</tt> is negative or greater than <tt>2</tt>.
89      */

90     public Integer JavaDoc[] getObjects(int n) {
91         if (dataObjects[n] == null) {
92             if (data[n] == null)
93                 data[n] = createList(n, size);
94             dataObjects[n] = new Integer JavaDoc[data[n].length];
95             for (int i = 0; i < data[n].length; i++)
96                 dataObjects[n][i] = new Integer JavaDoc(data[n][i]);
97         }
98         return dataObjects[n];
99     }
100
101     /**
102      * Returns an identifier for this data set.
103      *
104      * @return an identifier for this data set.
105      */

106     public String JavaDoc getId() {
107         return id;
108     }
109
110     /**
111      * Creates the list with the specified number.
112      *
113      * @param n
114      * the number of the list to create (0-2).
115      *
116      * @param size
117      * the size of the list to create.
118      *
119      * @return data list number <tt>n</tt> with size <tt>size</tt>.
120      */

121     protected abstract int[] createList(int n, int size);
122
123 }
Popular Tags