Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

PlotSwitch.java

Go to the documentation of this file.
00001 package cedar.jetweb.model.plots;
00002 
00003 import java.util.HashSet;
00004 import java.util.Iterator;
00005 
00006 import cedar.jetweb.db.DBPlotManager;
00007 import cedar.jetweb.Storeable;
00008 import cedar.jetweb.JetWebException;
00009 import cedar.jetweb.model.MCProcessType;
00010 import cedar.jetweb.model.Collision;
00011 
00018 public class PlotSwitch implements Storeable {
00019 
00020     private int id;
00021     private int plotId;
00022     private MCProcessType proc;
00023     private int procId;
00024     private String parameterName;
00025     private Double parameterValueLow = Double.NEGATIVE_INFINITY;
00026     private Double parameterValueHigh  = Double.POSITIVE_INFINITY;;
00027     private String generatorName;
00028     private double generatorVersion = -1.0;
00029 
00030     private static HashSet<String> allowedParameters;
00031 
00035     public PlotSwitch(int newId) throws JetWebException {
00036     id = newId;
00037     retrieve();
00038     } 
00039 
00043     public PlotSwitch() throws JetWebException {
00044     } 
00045 
00046 
00047     public boolean retrieve() throws JetWebException {
00048     try {
00049         DBPlotManager.selectPlotSwitch(this);       
00050     } catch (JetWebException jwe){
00051         throw jwe;
00052     }
00053     return true;
00054     }
00055 
00056     public boolean store() throws JetWebException {
00057 
00058     // If this switch has an Id, update it using this Id.
00059     if (id>0) {
00060         DBPlotManager.update(this);
00061         return false;
00062     }
00063 
00064     // If the switch currently has no id, must determine whether it is identical
00065     // to an existing switch. If it is, do nothing. If not, add it as a new switch.
00066 
00067     // Get the switches which are already in the DB.
00068     HashSet<PlotSwitch> slist = DBPlotManager.getSwitches(plotId);
00069     if (!slist.contains(this)){
00070         DBPlotManager.add(this);
00071         return true;
00072     }
00073     return false;
00074     }
00075 
00079     public int getId(){ return id; }
00080 
00084     public int getMCProcessTypeId(){ return procId; }
00085 
00089     public MCProcessType getMCProcessType(){
00090 
00091     //System.out.println("PlotSwitch: procId = "+procId);
00092      
00093     if (proc==null){
00094         proc=new MCProcessType(procId);
00095     }
00096     return proc;
00097     }
00098 
00102     public String getGeneratorName(){ return generatorName; }
00103 
00107     public double getGeneratorVersion(){ return generatorVersion; }
00108 
00112     public Double getParameterValueLow(){ return parameterValueLow; }
00113 
00117     public Double getParameterValueHigh(){ return parameterValueHigh; }
00118 
00122     public String getParameterName(){ return parameterName; }
00123 
00124 
00125     public void setGeneratorName(String gen){
00126     generatorName = gen;
00127     }
00128     public void setPlotId(int newId){
00129     plotId = newId;
00130     }
00131     public int getPlotId(){
00132     return plotId;
00133     }
00134     public void setGeneratorVersion(double vers){
00135     generatorVersion = vers;
00136     }
00137     public void setParameterName(String pname){
00138     parameterName = pname;
00139     }
00140     public void setParameterValueHigh(double val){
00141     parameterValueHigh = val;
00142     }
00143     public void setParameterValueLow(double val){
00144     parameterValueLow = val;
00145     }
00146     public void setMCProcessTypeId(int id){
00147     procId = id;
00148     }
00149 
00156     public boolean equals(Object obj){
00157 
00158     if (obj==null) { return false; }
00159 
00160     if ( !this.getClass().equals(obj.getClass())  ) { return false; }
00161 
00162     PlotSwitch ps = (PlotSwitch)obj;
00163     //System.out.println("Checking equality "+ps.getId()+" : "+id);
00164 
00165 
00166     if ( (ps.getId()>0) && id>0 ){
00167         return (id==ps.getId());
00168     } else {
00169 
00170         //System.out.println("here 1");
00171 
00172         if ( procId!=ps.getMCProcessTypeId() ) { return false; }
00173 
00174         //System.out.println("here 2");
00175 
00176         if (parameterName!=null) {
00177         if  (!parameterName.equals(ps.getParameterName())) {return false;}
00178         } else {
00179         if ( ps.getParameterName()!=null) { return false; }
00180         }
00181 
00182         //System.out.println("here 3");
00183 
00184         if (generatorName!=null) {      
00185             if ( !generatorName.equals(ps.getGeneratorName())) {return false;}
00186         } else {
00187         if ( ps.getGeneratorName()!=null ) { return false; }
00188         }
00189 
00190         //System.out.println("here 4");
00191 
00192         if (generatorVersion!=ps.getGeneratorVersion()) {return false; }
00193 
00194         boolean check = true;
00195         if ( parameterValueHigh!=ps.getParameterValueHigh() ) {
00196         // 1% accuracy check.
00197         check = check && ( Math.abs( parameterValueHigh-ps.getParameterValueHigh() )
00198                    / (Math.abs(ps.getParameterValueHigh())
00199                       +Math.abs(parameterValueHigh))
00200                    >0.01 ); 
00201         }
00202 
00203         if ( parameterValueLow!=ps.getParameterValueLow() ) {
00204         check = check && ( Math.abs( parameterValueLow-ps.getParameterValueLow() )
00205                    / (Math.abs(ps.getParameterValueLow())
00206                       +Math.abs(parameterValueLow))
00207                    >0.01 ); 
00208         }
00209 
00210         //System.out.println("here 5 "+check);
00211 
00212         return check;
00213     }
00214     }
00215 
00220     public static Iterator<String> getAllowedParameters(){
00221 
00222     return allowedParameters.iterator();
00223 
00224     }
00225 
00230     public static boolean isAllowedParameter(String parameter){
00231 
00232     if (allowedParameters.contains(parameter)) { return true; }
00233     return false;
00234 
00235     }
00236 
00237 
00243     public static synchronized void initializeParameterList(){
00244 
00245     allowedParameters = new HashSet<String>();
00246     allowedParameters.add("pthat");
00247     allowedParameters.add("Q2");
00248     } 
00249 
00250     public int hashCode(){ return 9999; }
00251 
00252     public static MCProcessType defaultProc(Collision c){
00253 
00254     MCProcessType proc = new MCProcessType();
00255     proc.setCollision(c);
00256     proc.setMCProcessName("High ET");
00257     return proc;
00258 
00259     }
00260 
00261 }
00262 
00263 
00264 
00265 
00266 
00267 
00268 
00269 
00270 
00271 
00272 
00273 
00274 
00275 
00276 
00277 
00278 

Generated Wed Jan 17 09:14:27 GMT 2007