KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > polepos > framework > TurnSetup


1 /*
2 This file is part of the PolePosition database benchmark
3 http://www.polepos.org
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program 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
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 MA 02111-1307, USA. */

19
20 package org.polepos.framework;
21
22 import java.util.*;
23
24 import org.polepos.*;
25
26
27 /**
28  * @author Herkules
29  */

30 public class TurnSetup implements Cloneable JavaDoc{
31     
32     
33     private final static PropertiesHandler mProperties = new PropertiesHandler(RunSeason.PROPERTIES);
34     
35     private final static String JavaDoc OBJECTCOUNT = "objects";
36     private final static String JavaDoc SELECTCOUNT = "selects";
37     private final static String JavaDoc UPDATECOUNT = "updates";
38     private final static String JavaDoc TREEWIDTH = "width";
39     private final static String JavaDoc TREEDEPTH = "depth";
40     private final static String JavaDoc COMMITINTERVAL = "commitinterval";
41     private final static String JavaDoc OBJECTSIZE = "size";
42
43     private final static String JavaDoc[] AVAILABLE_SETTINGS = new String JavaDoc[]{
44         OBJECTCOUNT,
45         SELECTCOUNT,
46         UPDATECOUNT,
47         TREEWIDTH,
48         TREEDEPTH,
49         COMMITINTERVAL,
50         OBJECTSIZE
51     };
52     
53     private Map<SetupProperty, SetupProperty> mSettings = new Hashtable<SetupProperty, SetupProperty>();
54     
55     private TurnSetup deepClone(){
56         TurnSetup res = null;
57         try {
58             res = (TurnSetup)this.clone();
59         } catch (CloneNotSupportedException JavaDoc e) {
60             e.printStackTrace();
61         }
62         res.mSettings = new Hashtable<SetupProperty, SetupProperty>();
63         for(SetupProperty sp : mSettings.keySet()){
64             res.mSettings.put(sp, sp);
65         }
66         return res;
67     }
68     
69     public static TurnSetup[] read(Circuit circuit){
70         
71         Vector<TurnSetup> vec = new Vector<TurnSetup>();
72         
73         for (int i = 0; i < AVAILABLE_SETTINGS.length; i++) {
74             
75             int[] values = null;
76             
77             try{
78                 values = mProperties.getIntArray(circuit.internalName() + "." + AVAILABLE_SETTINGS[i]);
79             }catch(Exception JavaDoc e){
80                 
81             }
82             
83             if(values!= null && values.length > 0){
84                 int len = values.length;
85                 
86                 // make sure that we have enough LapSetup objects in our vector
87
// and clone the last if we dont or create a first one
88
while(vec.size() < len){
89                     if(vec.size() > 0){
90                         vec.add((vec.get(vec.size() - 1)).deepClone());
91                     }else{
92                         vec.add(new TurnSetup());
93                     }
94                 }
95                 
96                 // pass values to all LapSetup objects and take the last value as
97
// the default if there are more than we have values
98
int j = 0;
99                 Iterator it = vec.iterator();
100                 while(it.hasNext()){
101                     TurnSetup ls = (TurnSetup)it.next();
102                     SetupProperty sp =new SetupProperty(AVAILABLE_SETTINGS[i], values[j]);
103                     ls.mSettings.put(sp, sp);
104                     if(j < values.length - 1){
105                         j++;
106                     }
107                 }
108             }
109         }
110         
111         TurnSetup[] res = new TurnSetup[vec.size()];
112         vec.toArray(res);
113         
114         return res;
115     }
116     
117     private int getSetting(String JavaDoc key){
118         SetupProperty p = mSettings.get(new SetupProperty(key, 0));
119         if(p != null){
120             return p.value();
121         }
122         return 0;
123     }
124     
125     public int getCommitInterval(){
126         return getSetting(COMMITINTERVAL);
127     }
128
129     public int getObjectCount(){
130         return getSetting(OBJECTCOUNT);
131     }
132     
133     public int getSelectCount(){
134         return getSetting(SELECTCOUNT);
135     }
136     
137     public int getUpdateCount(){
138         return getSetting(UPDATECOUNT);
139     }
140     
141     public int getTreeWidth(){
142         return getSetting(TREEWIDTH);
143     }
144     
145     public int getTreeDepth(){
146         return getSetting(TREEDEPTH);
147     }
148     
149     public int getObjectSize(){
150         return getSetting(OBJECTSIZE);
151     }
152     
153     public int getMostImportantValueForGraph(){
154         for (int i = 0; i < AVAILABLE_SETTINGS.length; i++) {
155             int val = getSetting(AVAILABLE_SETTINGS[i]);
156             if(val > 0){
157                 return val;
158             }
159         }
160         return 0;
161     }
162     
163     public String JavaDoc getMostImportantNameForGraph(){
164         for (int i = 0; i < AVAILABLE_SETTINGS.length; i++) {
165             int val = getSetting(AVAILABLE_SETTINGS[i]);
166             if(val > 0){
167                 return AVAILABLE_SETTINGS[i];
168             }
169         }
170         return "";
171     }
172     
173     public Set<SetupProperty> properties() {
174         return Collections.unmodifiableSet(mSettings.keySet());
175     }
176     
177 }
178
Free Books   Free Magazines  
Popular Tags