001: /*
002: * Primitive Collections for Java.
003: * Copyright (C) 2003 Søren Bak
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package bak.pcj.benchmark;
020:
021: import bak.pcj.list.IntList;
022:
023: /**
024: * This class represents data sets for benchmarks. A data set contains
025: * three lists of equal length. Each list has only distinct values
026: * and the lists are all disjoint.
027: *
028: * @author Søren Bak
029: * @version 1.0 2003/5/1
030: * @since 1.0
031: */
032: public abstract class DataSet {
033:
034: private int[][] data;
035: private Integer[][] dataObjects;
036: private String id;
037: private int size;
038:
039: /**
040: * Creates a new data set with a specified id and size.
041: *
042: * @param id
043: * the identifier of the new data set. Only used for
044: * formatting a report.
045: *
046: * @param size
047: * the size of the lists in the new data set.
048: *
049: * @throws NullPointerException
050: * if <tt>id</tt> is <tt>null</tt>.
051: *
052: * @throws IllegalArgumentException
053: * if <tt>size</tt> is not positive.
054: */
055: protected DataSet(String id, int size) {
056: if (id == null)
057: throw new NullPointerException();
058: if (size <= 0)
059: throw new IllegalArgumentException();
060: this .id = id;
061: this .size = size;
062: data = new int[3][];
063: dataObjects = new Integer[3][];
064: }
065:
066: /**
067: * Returns a specified list of this data set.
068: *
069: * @param n
070: * the index of the list to return.
071: *
072: * @throws IndexOutOfBoundsException
073: * if <tt>n</tt> is negative or greater than <tt>2</tt>.
074: */
075: public int[] get(int n) {
076: if (data[n] == null)
077: data[n] = createList(n, size);
078: return data[n];
079: }
080:
081: /**
082: * Returns a specified list of this data set as objects.
083: *
084: * @param n
085: * the index of the list to return.
086: *
087: * @throws IndexOutOfBoundsException
088: * if <tt>n</tt> is negative or greater than <tt>2</tt>.
089: */
090: public Integer[] getObjects(int n) {
091: if (dataObjects[n] == null) {
092: if (data[n] == null)
093: data[n] = createList(n, size);
094: dataObjects[n] = new Integer[data[n].length];
095: for (int i = 0; i < data[n].length; i++)
096: dataObjects[n][i] = new Integer(data[n][i]);
097: }
098: return dataObjects[n];
099: }
100:
101: /**
102: * Returns an identifier for this data set.
103: *
104: * @return an identifier for this data set.
105: */
106: public String 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: }
|