1 19 20 package org.polepos.framework; 21 22 import java.util.*; 23 24 import org.polepos.*; 25 26 27 30 public class TurnSetup implements Cloneable { 31 32 33 private final static PropertiesHandler mProperties = new PropertiesHandler(RunSeason.PROPERTIES); 34 35 private final static String OBJECTCOUNT = "objects"; 36 private final static String SELECTCOUNT = "selects"; 37 private final static String UPDATECOUNT = "updates"; 38 private final static String TREEWIDTH = "width"; 39 private final static String TREEDEPTH = "depth"; 40 private final static String COMMITINTERVAL = "commitinterval"; 41 private final static String OBJECTSIZE = "size"; 42 43 private final static String [] AVAILABLE_SETTINGS = new String []{ 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 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 e){ 80 81 } 82 83 if(values!= null && values.length > 0){ 84 int len = values.length; 85 86 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 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 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 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
| Popular Tags
|