001: /*
002: This file is part of the PolePosition database benchmark
003: http://www.polepos.org
004:
005: This program is free software; you can redistribute it and/or
006: modify it under the terms of the GNU General Public License
007: as published by the Free Software Foundation; either version 2
008: of the License, or (at your option) any later version.
009:
010: This program 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
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public
016: License along with this program; if not, write to the Free
017: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
018: MA 02111-1307, USA. */
019:
020: package org.polepos.framework;
021:
022: import java.util.*;
023:
024: import org.polepos.*;
025:
026: /**
027: * @author Herkules
028: */
029: public class TurnSetup implements Cloneable {
030:
031: private final static PropertiesHandler mProperties = new PropertiesHandler(
032: RunSeason.PROPERTIES);
033:
034: private final static String OBJECTCOUNT = "objects";
035: private final static String SELECTCOUNT = "selects";
036: private final static String UPDATECOUNT = "updates";
037: private final static String TREEWIDTH = "width";
038: private final static String TREEDEPTH = "depth";
039: private final static String COMMITINTERVAL = "commitinterval";
040: private final static String OBJECTSIZE = "size";
041:
042: private final static String[] AVAILABLE_SETTINGS = new String[] {
043: OBJECTCOUNT, SELECTCOUNT, UPDATECOUNT, TREEWIDTH,
044: TREEDEPTH, COMMITINTERVAL, OBJECTSIZE };
045:
046: private Map<SetupProperty, SetupProperty> mSettings = new Hashtable<SetupProperty, SetupProperty>();
047:
048: private TurnSetup deepClone() {
049: TurnSetup res = null;
050: try {
051: res = (TurnSetup) this .clone();
052: } catch (CloneNotSupportedException e) {
053: e.printStackTrace();
054: }
055: res.mSettings = new Hashtable<SetupProperty, SetupProperty>();
056: for (SetupProperty sp : mSettings.keySet()) {
057: res.mSettings.put(sp, sp);
058: }
059: return res;
060: }
061:
062: public static TurnSetup[] read(Circuit circuit) {
063:
064: Vector<TurnSetup> vec = new Vector<TurnSetup>();
065:
066: for (int i = 0; i < AVAILABLE_SETTINGS.length; i++) {
067:
068: int[] values = null;
069:
070: try {
071: values = mProperties.getIntArray(circuit.internalName()
072: + "." + AVAILABLE_SETTINGS[i]);
073: } catch (Exception e) {
074:
075: }
076:
077: if (values != null && values.length > 0) {
078: int len = values.length;
079:
080: // make sure that we have enough LapSetup objects in our vector
081: // and clone the last if we dont or create a first one
082: while (vec.size() < len) {
083: if (vec.size() > 0) {
084: vec.add((vec.get(vec.size() - 1)).deepClone());
085: } else {
086: vec.add(new TurnSetup());
087: }
088: }
089:
090: // pass values to all LapSetup objects and take the last value as
091: // the default if there are more than we have values
092: int j = 0;
093: Iterator it = vec.iterator();
094: while (it.hasNext()) {
095: TurnSetup ls = (TurnSetup) it.next();
096: SetupProperty sp = new SetupProperty(
097: AVAILABLE_SETTINGS[i], values[j]);
098: ls.mSettings.put(sp, sp);
099: if (j < values.length - 1) {
100: j++;
101: }
102: }
103: }
104: }
105:
106: TurnSetup[] res = new TurnSetup[vec.size()];
107: vec.toArray(res);
108:
109: return res;
110: }
111:
112: private int getSetting(String key) {
113: SetupProperty p = mSettings.get(new SetupProperty(key, 0));
114: if (p != null) {
115: return p.value();
116: }
117: return 0;
118: }
119:
120: public int getCommitInterval() {
121: return getSetting(COMMITINTERVAL);
122: }
123:
124: public int getObjectCount() {
125: return getSetting(OBJECTCOUNT);
126: }
127:
128: public int getSelectCount() {
129: return getSetting(SELECTCOUNT);
130: }
131:
132: public int getUpdateCount() {
133: return getSetting(UPDATECOUNT);
134: }
135:
136: public int getTreeWidth() {
137: return getSetting(TREEWIDTH);
138: }
139:
140: public int getTreeDepth() {
141: return getSetting(TREEDEPTH);
142: }
143:
144: public int getObjectSize() {
145: return getSetting(OBJECTSIZE);
146: }
147:
148: public int getMostImportantValueForGraph() {
149: for (int i = 0; i < AVAILABLE_SETTINGS.length; i++) {
150: int val = getSetting(AVAILABLE_SETTINGS[i]);
151: if (val > 0) {
152: return val;
153: }
154: }
155: return 0;
156: }
157:
158: public String getMostImportantNameForGraph() {
159: for (int i = 0; i < AVAILABLE_SETTINGS.length; i++) {
160: int val = getSetting(AVAILABLE_SETTINGS[i]);
161: if (val > 0) {
162: return AVAILABLE_SETTINGS[i];
163: }
164: }
165: return "";
166: }
167:
168: public Set<SetupProperty> properties() {
169: return Collections.unmodifiableSet(mSettings.keySet());
170: }
171:
172: }
|